1

I am using this library https://pub.dartlang.org/packages/flutter_cache_manager#-readme-tab- and I have 2 questions. Firstly, it is unclear to me whether the getFile(url) function automatically caches the file that is returned or whether I must call putFile() after it is returned.

Secondly, I see that you can override BaseCacheManager to set a maxAgeCacheObject. Does the OS automatically delete files that have expired or must I make sure they are cleaned.

Thanks for the help :)

ebg11
  • 906
  • 1
  • 12
  • 33

1 Answers1

1

ad 1) The getFile(url) method will "automatically" cache the result. The putFile() method is only available to eagerly precache data.

ad 2) Both, You should make sure you have a reasonable upper limit. But since files are stored in a temporary directory which the OS is allowed to delete, the files will be removed if the device runs out of storage. --- FWIW - No, the OS does not remove files which are too old, but the cache manager will remove objects which are older than maxAgeCacheObject. (The OS does not know about how old a file can be, it might start deleting the oldest files first, but there is no guarantee for this.)

Herbert Poul
  • 4,512
  • 2
  • 31
  • 48
  • Thanks for your answer herbert. Could you tell me when the cache manager removes files with an age greater that the maxAgeCacheObject... For example does it do this when the singleton is initialized for the first time? – ebg11 Apr 09 '19 at 19:58
  • @ebg11 well right now, it does so at *every access* https://github.com/renefloor/flutter_cache_manager/blob/master/lib/src/cache_store.dart#L132-L137 .. (the cache manager creates a new sqlite connection for (basically) every cache access - https://github.com/renefloor/flutter_cache_manager/blob/master/lib/src/cache_store.dart#L79-L87 which imo is pretty strange, especially since it's afaik best practice to never close sqlite on mobile https://stackoverflow.com/a/44578432/109219 but that's somehow a bit off topic :) – Herbert Poul Apr 09 '19 at 20:24
  • Appreciate your help :) – ebg11 Apr 19 '19 at 15:34