How to use CachedNetworkImage with different Cache Managers?

293 Views Asked by At

Im caching images in my Flutter App which im fetching from my Firebase Storage. I use the cached_network_image package and the flutter_cache_manager for the caching part.

Some images I just want to cache for a few days, others for a very long time or when the user deletes them. Is there a way to do that with this package? I know I could create different custom cache manager and set different stale periods. Would that be the way I should go for? Or should I use the the package only for the short time caching and another method for the long term storing.

Thanks in advance

1

There are 1 best solutions below

1
Rod Rodrigues On

Set the duration according to your needs.

final CacheManager cacheManager = CacheManager(
    Config(
        'the_key',
        stalePeriod: const Duration(days: 3),//secs, mins...
    ),
);

If it's something that rarely changes you can even increase the number of days. I strongly recommend setting a key so maintenance is easier whenever you need to do it.