Java Windows上的应用程序缓存应该存储在哪里?

Java Windows上的应用程序缓存应该存储在哪里?,java,windows,caching,Java,Windows,Caching,我有一个Windows应用程序,可以下载各种文件。我想缓存此文件,但我不确定将缓存放在何处。它应该存在于用户的主文件夹中,这样他们就可以一直访问,但我不认为像文档这样的文件夹是合适的 与我在macOS和Linux上寻找的功能相当的是: ~/Library/Caches/MyApp ~/.cache/MyApp Windows上的应用程序缓存应该存储在哪里 请注意,与中不同,我不是在询问临时文件。我的缓存应该跨会话重复使用 请注意,我不是在构建Windows应用商店应用程序。不需要漫游的每

我有一个Windows应用程序,可以下载各种文件。我想缓存此文件,但我不确定将缓存放在何处。它应该存在于用户的主文件夹中,这样他们就可以一直访问,但我不认为像
文档这样的文件夹是合适的

与我在macOS和Linux上寻找的功能相当的是:

  • ~/Library/Caches/MyApp
  • ~/.cache/MyApp
Windows上的应用程序缓存应该存储在哪里


请注意,与中不同,我不是在询问临时文件。我的缓存应该跨会话重复使用



请注意,我不是在构建Windows应用商店应用程序。

不需要漫游的每用户数据应存储在下。您可以通过调用(或在.NET中)来获取此路径。如果您需要数据在域环境中漫游,但不适合大文件,请改用
CSIDL\u APPDATA

每个用户不需要漫游的数据应存储在下。您可以通过调用(或在.NET中)来获取此路径。如果您需要数据在域环境中漫游,但对于大文件来说这不是一个好主意,请改用
CSIDL\u APPDATA

我的最终解决方案:

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");
}
我的最终解决方案:

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");
}

没有标记用于存储缓存数据的特定位置,AppData用于当前用户的特定于应用程序的数据(CSIDL_AppData),我将使用它。没有标记用于存储缓存数据的特定位置,AppData用于当前用户的特定于应用程序的数据(CSIDL_AppData),我将使用它。