flutter_cache_manager 0.2.0+1

  • README.md
  • Installing
  • Versions
  • 92


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.


    var cacheManager = await CacheManager.getInstance();
    var file = await cacheManager.getFile(url);


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.

[0.2.0] - 2018-10-13

  • Fixed library compatibility issue

[0.1.2] - 2018-08-30

  • Fixed library compatibility issue
  • Improved some synchronization

[0.1.1] - 2018-04-27

  • Fixed some issues when file could not be downloaded the first time it is trying to be retrieved.

[0.1.0] - 2018-04-14

  • Fixed ConcurrentModificationError in cache cleaning
  • Added optional headers
  • Moved to Dart 2.0

[0.0.4+1] - 2018-02-16

  • Fixed nullpointer when non-updated file (a 304 response) has no cache-control period.

[0.0.4] - 2018-01-31

  • Fixed issues with cache cleaning

[0.0.3] - 2018-01-08

  • Fixed relative paths on iOS.

[0.0.2] - 2017-12-29

  • Did some refactoring and made a useful readme.

[0.0.1] - 2017-12-28

  • Extracted the cache manager from cached_network_image

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_cache_manager: ^0.2.0+1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_cache_manager/flutter_cache_manager.dart';
Version Uploaded Documentation Archive
0.2.0+1 Nov 12, 2018 Go to the documentation of flutter_cache_manager 0.2.0+1 Download flutter_cache_manager 0.2.0+1 archive
0.2.0 Oct 13, 2018 Go to the documentation of flutter_cache_manager 0.2.0 Download flutter_cache_manager 0.2.0 archive
0.1.2 Aug 30, 2018 Go to the documentation of flutter_cache_manager 0.1.2 Download flutter_cache_manager 0.1.2 archive
0.1.1 Apr 27, 2018 Go to the documentation of flutter_cache_manager 0.1.1 Download flutter_cache_manager 0.1.1 archive
0.1.0 Apr 14, 2018 Go to the documentation of flutter_cache_manager 0.1.0 Download flutter_cache_manager 0.1.0 archive
0.0.4+1 Feb 16, 2018 Go to the documentation of flutter_cache_manager 0.0.4+1 Download flutter_cache_manager 0.0.4+1 archive
0.0.4 Jan 31, 2018 Go to the documentation of flutter_cache_manager 0.0.4 Download flutter_cache_manager 0.0.4 archive
0.0.3 Jan 8, 2018 Go to the documentation of flutter_cache_manager 0.0.3 Download flutter_cache_manager 0.0.3 archive
0.0.2 Dec 29, 2017 Go to the documentation of flutter_cache_manager 0.0.2 Download flutter_cache_manager 0.0.2 archive
0.0.1 Dec 28, 2017 Go to the documentation of flutter_cache_manager 0.0.1 Download flutter_cache_manager 0.0.1 archive

All 14 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/cache_object.dart. (-0.50 points)

Analysis of lib/src/cache_object.dart reported 1 hint:

line 96 col 48: 'onError' is deprecated and shouldn't be used.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use flutter_cache_manager.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
http >=0.11.0 <0.13.0 0.12.0
path_provider ^0.4.0 0.4.1
shared_preferences ^0.4.0 0.4.3
synchronized ^1.5.1 1.5.3
uuid ^1.0.3 1.0.3
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
http_parser 3.1.3
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
vector_math 2.0.8