Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/flutter_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,24 @@ class CacheManager {
//Remove oldest objects when cache contains to many items
if (_cacheData.length > maxNrOfCacheObjects) {
var allValues = _cacheData.values.toList();
allValues.sort((c1, c2) => c2.touched.compareTo(c1.touched)); // sort OLDEST first
allValues.sort((c1, c2) => c1.touched.compareTo(c2.touched)); // sort OLDEST first
var oldestValues = allValues.take( _cacheData.length - maxNrOfCacheObjects); // get them
oldestValues.forEach( (item) async {await _removeFile(item);} ); //remove them
}
}

_removeFile(CacheObject cacheObject) async {
//Ensure the file has been downloaded
if (cacheObject.relativePath == null) {
return;
}

_cacheData.remove(cacheObject.url);

var file = new File(await cacheObject.getFilePath());
if (await file.exists()) {
file.delete();
}
_cacheData.remove(cacheObject.url);
}

///Get the file from the cache or online. Depending on availability and age
Expand Down