flutter_cache_manager 0.0.4+1

  • README.md
  • Installing
  • Versions
  • 81


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.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

1. Depend on it

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

  flutter_cache_manager: "^0.0.4+1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or 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.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


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 16, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1
  • Flutter: 0.0.22


Describes how popular the package is relative to other packages. [more]
72 / 100
Code health derived from static analysis. [more]
99 / 100
Reflects how tidy and up-to-date the package is. [more]
76 / 100
Overall score:
Weighted score of the above. [more]


Detected platforms: unsure

Error(s) prevent platform classification.


  • Fix dependencies in pubspec.yaml.

    Running flutter packages pub upgrade failed with the following output:

    ERR: Invalid argument(s): Minimum version ("2.0.0-dev.23.0") must be less than maximum ("2.0.0-dev.16.0").
    ERR: package:pub_semver/src/version_range.dart 59         new VersionRange
     package:pub/src/pubspec.dart 366                     Pubspec._ensureEnvironment
     package:pub/src/pubspec.dart 331                     Pubspec.dartSdkConstraint
     package:pub/src/solver/backtracking_solver.dart 511  BacktrackingSolver._checkPubspecMatchesSdkConstraint
     package:pub/src/solver/backtracking_solver.dart 474  BacktrackingSolver._checkVersion
     ===== asynchronous gap ===========================
     package:pub/src/solver/backtracking_solver.dart 432  BacktrackingSolver._findValidVersion.<fn>
     ===== asynchronous gap ===========================
     dart:async                                           Future.doWhile
     package:pub/src/solver/backtracking_solver.dart 430  BacktrackingSolver._findValidVersion
     package:pub/src/solver/backtracking_solver.dart 337  BacktrackingSolver._versionQueueFor
     ===== asynchronous gap ===========================
     package:pub/src/solver/backtracking_solver.dart 290  BacktrackingSolver._solve.<fn>
     ===== asynchronous gap ===========================
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/backtracking_solver.dart 315  BacktrackingSolver._solve.<fn>
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 64     VersionSelection.select
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 91     VersionSelection._addDependencies
    ERR: This is an unexpected error. Please run
         pub --trace upgrade --verbosity io --no-precompile
     and include the logs in an issue on https://github.com/dart-lang/pub/issues/new
  • Fix platform conflicts.

    Make sure none of the libraries use mutually exclusive dependendencies.

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • The description is too short.

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

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    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 >=1.8.0 <2.0.0