I have a Windows application that downloads various files. I would like to cache this files but I am unsure where to put the cache. It should live in the user's home folder, so that they always have access, but I don't think that folders such as Documents are appropriate.
The equivalent of what I am looking for on macOS and Linux are:
~/Library/Caches/MyApp~/.cache/MyAppWhere should application caches be stored on Windows?
Note that unlike in this question, I am not asking about temp files. My cache should be re-used across sessions.
Note that I am not building a Windows Store app.
My final solution:
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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With