我有一个下载各种文件的 Windows 应用程序。我想缓存这些文件,但我不确定将缓存放在哪里。它应该位于用户的主文件夹中,以便他们始终可以访问,但我认为 Documents
等文件夹不合适。
我在 macOS 和 Linux 上寻找的等效项是:
~/Library/Caches/MyApp
~/.cache/MyApp
应用程序缓存应该存储在 Windows 上的哪里?
<小时/>请注意,与 this question 不同,我不是在询问临时文件。我的缓存应该在 session 之间重复使用。
<小时/>请注意,我不是在构建 Windows 应用商店应用程序。
最佳答案
我的最终解决方案:
public static Path getCacheFolder(final String osName, final FileSystem fs) {
Objects.requireNotNull(osName, "osName is null");
Objects.requireNotNull(fs, "fs is null");
// macOS
if (osName.toLowerCase().contains("mac")) {
return fs.getPath(System.getProperty("user.home"), "Library", "Caches");
}
// Linux
if (osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) {
return fs.getPath(System.getProperty("user.home"), ".cache");
}
// Windows
if (osName.contains("indows")) {
return fs.getPath(System.getenv("LOCALAPPDATA"), "Caches");
}
// A reasonable fallback
return fs.getPath(System.getProperty("user.home"), "caches");
}
关于java - 我应该在 Windows 上将应用程序缓存存储在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44718524/