Giter VIP home page Giter VIP logo

flutter_cache_manager's Introduction

flutter_cache_manager

pub package Donate

A CacheManager to download and cache files in the cache directory of the app. 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 CacheManager can be changed. All these preferences are statics and should be set before the first use of the CacheManager, so preferably directly on 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 CacheManager 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.

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.

flutter_cache_manager's People

Contributors

mshipton avatar renefloor avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.