skip to Main Content

Just want to get clarification on below coding. cacheDuration set seconds to 0 caches avatar.jpg for the app session, any subsequent used is getting from cache. Once app is closed, avatar.jpg will be deallocated from cache. Am I right ?

CachedNetworkImage(
imageUrl: ‘https://example.com/avatar.jpg’,
cacheDuration: const Duration(seconds: 0),
);

2

Answers


  1. The image is stored in memory during your session, rather than on your device’s disk. It will be removed from the cache once you close the app.

    Login or Signup to reply.
  2. cached_network_image use the flutter_cache_manager library to manage cached files. Here is what the doc says :

    the cache deletes files when there are too many, ordered by last use, and when files just haven’t been used for longer than the stale period

    So I think your solution with a Duration of 0 will work but you can also try a cleaner solution (I think): try to delete all the cached image at the start of your app (in the main() method for exemple).

    To clean all cache you can try this (it will remove old cached images):

    await DefaultCacheManager().emptyCache();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search