defaultCacheBasePath method
The operating system's cache directory for name: ~/Library/Caches
on macOS, %LOCALAPPDATA% on Windows, $XDG_CACHE_HOME or ~/.cache
elsewhere. With no home directory in the environment — some service
accounts — it falls back to the current directory; set cacheDirEnv or
pass an override there instead.
Implementation
String defaultCacheBasePath({Map<String, String>? environment}) {
final env = environment ?? Platform.environment;
if (Platform.isMacOS) {
return _join([env['HOME'] ?? '.', 'Library', 'Caches', name]);
}
if (Platform.isWindows) {
final local =
env['LOCALAPPDATA'] ??
_join([env['USERPROFILE'] ?? '.', 'AppData', 'Local']);
return _join([local, name]);
}
final xdg = env['XDG_CACHE_HOME'];
if (xdg != null && xdg.trim().isNotEmpty) {
return _join([xdg.trim(), name]);
}
return _join([env['HOME'] ?? '.', '.cache', name]);
}