Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
738 stars 427 forks source link

Store cache in $XDG_CACHE_HOM or ~/.cache #416

Open solsticedhiver opened 1 year ago

solsticedhiver commented 1 year ago

On linux, /tmp is most of the time an in memory filesystem, wipe out after a reboot.

So for a long term cache, this does not work, unless you can specify a custom location. I can't find out how to specify a said custom location. Where is the doc? How do you use FileSystem() or LocalFileSystem() (not really user friendly API)

You should be able to choose where the cache is stored, and a default location better be $XDG_CACHE_HOME if set or else $HOME/.cache on linux.

/tmp is for temporary file not cache

jpnurmi commented 10 months ago

Please consider using getApplicationCachePath() introduced in path_provider 2.1.0:

Notice that /tmp may be unsuitable for caching on systems with multiple users. For example, run the cached_network_image example first as user A and then as user B on Ubuntu:

PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc555ac0-23b8-11ee-8203-690c79df21e0.jpg' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc555ac0-23b8-11ee-8203-690c79df21e0.jpg' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://notAvalid.uri with error:
ClientException with SocketException: Failed host lookup: 'notavalid.uri' (OS Error: No address associated with hostname, errno = -5), uri=https://notavalid.uri
flutter: CacheManager: Failed to download file from https://via.placeholder.com/300x150 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc854460-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/200x150 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc854461-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/350x200 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc854462-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc854461-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/350x150 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc856b70-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/300x300 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc856b71-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc856b70-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc856b71-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)