flutter_cache_store icon indicating copy to clipboard operation
flutter_cache_store copied to clipboard

Files are deleted from Cache before Cache Policy rules were completed

Open isaacfi opened this issue 3 years ago • 1 comments

I tried to use all the Policies that you sugested in the documentation, but the files are only available for few seconds. Can you provide an example? I may forget something because the files are deleted when I tried to gets its content after almost 20 seconds.

class LastDownloadedCachePolicy extends CacheControlPolicy {
  LastDownloadedCachePolicy({int maxCount = 999})
      : super(
          maxCount: maxCount,
          minAge: Duration(days: 5),
          maxAge: Duration(days: 30),
        );

  @override
  String generateFilename({final String key, final String url}) => key;
}

var store = await CacheStore.getInstance(
        policy: LastDownloadedCachePolicy(), fetch: _fetchFile);
final file = await store.getFile('https://avatars.githubusercontent.com/u/647070?s=460&u=b85f224c333f371142df249b17012c5f8fe66cf2&v=4', key: 'myFile')

using Android adb shell:

lroot@vbox86p:/data/data/com.example.myApp/cache/cache_store # 
ls
root@vbox86p:/data/data/com.example.myApp/cache/cache_store # 

All the cache was cleared.

BR.

isaacfi avatar Mar 06 '21 04:03 isaacfi

var store supposes to be an instance only created once when your app starting up. As long as you create another instance with the same namespace, it will override previous one and could clear the cache if not persistented.

eGust avatar Mar 22 '21 06:03 eGust