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
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
CacheManager.maxNrOfCacheObjects = 200;
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.
Add this to your package's pubspec.yaml file:
dependencies: flutter_cache_manager: "^0.0.4+1"
You can install packages from the command line:
$ pub get
$ flutter packages get
Alternatively, your editor might support
pub get or
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
|0.0.4+1||Feb 16, 2018|
|0.0.4||Jan 31, 2018|
|0.0.3||Jan 8, 2018|
|0.0.2||Dec 29, 2017|
|0.0.1||Dec 28, 2017|
We analyzed this package, and provided a score, details, and suggestions below.
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]
Detected platforms: unsure
Error(s) prevent platform classification.
Fix dependencies in
flutter packages pub upgradefailed 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
dartanalyzerreported 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:
example.dartor you could also use
|Dart SDK||>=1.8.0 <2.0.0|