flutter_cache_manager 0.1.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 94

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.

[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

1. Depend on it

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


dependencies:
  flutter_cache_manager: "^0.1.0"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support 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.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
0.1.0-rc.1 Mar 24, 2018 Go to the documentation of flutter_cache_manager 0.1.0-rc.1 Download flutter_cache_manager 0.1.0-rc.1 archive

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6
  • Flutter: 0.3.2

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
88 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
94
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

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

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 4 hints.

    Run flutter format to format lib/flutter_cache_manager.dart.

    Strong-mode analysis of lib/src/cache_object.dart gave the following hint:

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
http ^0.11.3+14 0.11.3+16
path_provider ^0.4.0 0.4.0
shared_preferences ^0.4.0 0.4.1
synchronized ^1.3.0 1.4.0
uuid ^0.5.3 0.5.3 1.0.0
Transitive dependencies
async 2.0.6
charcode 1.1.1
collection 1.14.6 1.14.9
convert 2.0.1
crypto 2.0.2+1
http_parser 3.1.1
meta 1.1.2
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
vector_math 2.0.6