flutter_cache_manager 0.3.2

  • README.md
  • Example
  • Installing
  • Versions
  • 99

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.

The more basic usage is explained here. See the complete docs for more info.

Usage #

The cache manager can be used to get a file on various ways The easiest way to get a single file is call .getSingleFile.

    var file = await DefaultCacheManager().getSingleFile(url);

getFile(url) returns a stream with the first result being the cached file and later optionally the downloaded file.

downloadFile(url) directly downloads from the web.

getFileFromCache only retrieves from cache and returns no file when the file is not in the cache.

putFile gives the option to put a new file into the cache without downloading it.

removeFile removes a file from the cache.

emptyCache removes all files from the cache.

Settings #

The cache manager is customizable by extending the BaseCacheManager. Below is an example with other settings for the maximum age of files, maximum number of objects and a custom http getter. The key parameter in the constructor and the getFilePath method are mandatory.

class CustomCacheManager extends BaseCacheManager {
  static const key = "customCache";

  static CustomCacheManager _instance;

  factory CustomCacheManager() {
    if (_instance == null) {
      _instance = new CustomCacheManager._();
    return _instance;

  CustomCacheManager._() : super(key,
      maxAgeCacheObject: Duration(days: 7),
      maxNrOfCacheObjects: 20,
      fileFetcher: _customHttpGetter);

  Future<String> getFilePath() async {
    var directory = await getTemporaryDirectory();
    return p.join(directory.path, key);

  static Future<FileFetcherResponse> _customHttpGetter(String url, {Map<String, String> headers}) async {
    // Do things with headers, the url or whatever.
    return HttpFileFetcherResponse(await http.get(url, headers: headers));

How it works #

By default 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 a database using sqflite. The file name of the database is the key of the cacheManager, that's why that has to be unique.

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

[0.3.2] - 2019-03-06

  • Fixed image loading after loading failed once.

[0.3.1] - 2019-02-27

  • Added method to clear cache

[0.3.0] - 2019-02-18

  • Complete refactor of library
  • Use of SQFlite instead of shared preferences for cache info
  • Added the option to use a custom file fetcher (for example for firebase)
  • Support for AndroidX

[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


example #

A new Flutter project.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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

  flutter_cache_manager: ^0.3.2

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.3.2 Mar 6, 2019 Go to the documentation of flutter_cache_manager 0.3.2 Download flutter_cache_manager 0.3.2 archive
0.3.1 Feb 27, 2019 Go to the documentation of flutter_cache_manager 0.3.1 Download flutter_cache_manager 0.3.1 archive
0.3.0 Feb 18, 2019 Go to the documentation of flutter_cache_manager 0.3.0 Download flutter_cache_manager 0.3.0 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

All 22 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 Apr 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/web_helper.dart.

Run flutter format to format lib/src/web_helper.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+2
path ^1.6.2 1.6.2
path_provider ^0.5.0+1 0.5.0+1
sqflite ^1.1.0 1.1.5
synchronized ^2.0.2 2.1.0
uuid ^2.0.0 2.0.1
Transitive dependencies
async 2.2.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
http_parser 3.1.3
meta 1.1.6 1.1.7
pedantic 1.5.0
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
test ^1.3.0