Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter flutter logo cache manager

a cache manager to download and cache files in the cache directory of the app made on flutter. various settings on how long to keep a file can be changed.

it uses the cache-control http header to efficiently retrieve files.

usage

    var cachemanager = await cachemanager.getinstance();
    var file = await cachemanager.getfile(url);

settings

some settings of the cache manager can be changed.
all these preferences are statics and should be set before the first use of the cache manager, so preferably directly on the start of your app.

for extra logging set:

  cachemanager.showdebuglogs = true;

the cache can be cleaned after it is used to get a file. by default this happens once every week. you can change this by setting inbetweencleans.

  cachemanager.inbetweencleans = new duration(days: 7);

the cache manager checks for two things, for objects that are too old and the size of the cache.

by default it removes objects that haven’t been used for 30 days. set this by maxagecacheobject. *this is not about when the object is first downloaded, but when it is used the last.

  cachemanager.maxagecacheobject = new duration(days: 30);

by default the cache size is set to 200, when the cache grows beyond this it will remove the oldest objects again by when last used. set this with maxnrofcacheobjects.

  cachemanager.maxnrofcacheobjects = 200;

how it works

the cached files are stored in the temporary directory of the app. this means the os can delete the files any time.

flutter generic cache manager
flutter generic cache manager

information about the files is stored in the shared preferences with the key “lib_cached_image_data”. (because images was the first use of this library :)) the date when the cache is last cleaned is stored as “lib_cached_image_data_last_clean”.

this cache information contains the end date till when the file is valid and the etag to use with the http cache-control.

download the full project for this post from the following button

this source is fully free for all time

download as zip


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top