Skip to content

Commit

Permalink
Merge branch 'develop-evict' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn00 committed Jul 31, 2024
2 parents c3fce5b + 2a79666 commit a1b4955
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 15 deletions.
64 changes: 49 additions & 15 deletions flutter_cache_manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,102 @@
## [3.3.4] - 2023-12-05

* [Bugfix] For a previously cached file that got removed on the server, now evicts that file on 404 and notifies listeners.

## [3.3.3] - 2024-07-23

* Updates dependencies ([#457](https://github.com/Baseflow/flutter_cache_manager/pull/457))

## [3.3.2] - 2024-04-25

* Updates dependencies to their latest versions.

## [3.3.1] - 2023-07-03

* Support Dart 3.0.0 for http ^1.0.0 and file ^7.0.0
* Update example
* Add topics

## [3.3.0] - 2021-11-29

* Added option to manage the log level. Doesn't print failed downloads by default anymore. You can set it like this:

```dart
CacheManager.logLevel = CacheManagerLogLevel.verbose;
```

## [3.2.0] - 2021-11-27

* [Bugfix] getSingleFile now downloads a new file before completing as the outdated file might have been deleted.

## [3.1.3] - 2021-11-05

* Disabled resizing of cached gifs as this was broken.

## [3.1.2] - 2021-06-17

* removeFile function now completes after the file is removed from disk and not earlier ([#323](https://github.com/Baseflow/flutter_cache_manager/pull/323))
* Image resizing doesn't block ui anymore and doesn't use image package but existing Flutter components ([#319](https://github.com/Baseflow/flutter_cache_manager/pull/319))

## [3.1.1] - 2021-06-03

* Move File to separate file. You can add it using the following import:

```dart
import 'package:flutter_cache_manager/file.dart' as cache_file;
```

## [3.1.0] - 2021-05-28

* Export File from package file ([#302](https://github.com/Baseflow/flutter_cache_manager/pull/302))
* Bugfix for eTag on Flutter Web ([#304](https://github.com/Baseflow/flutter_cache_manager/pull/315))
* Bugfix for loading multiple images simultaneously ([#315](https://github.com/Baseflow/flutter_cache_manager/pull/315))

## [3.0.2] - 2021-05-10

* Include rxdart 0.27 as possible dependency

## [3.0.1] - 2021-03-29

* Include file 6.0.0 as possible dependency

## [3.0.0] - 2021-03-27

* Bug fix on removing a relatively new file from cache
* Migration to nullsafety.

## [3.0.0-nullsafety.3] - 2021-03-26

* Add null-check on id in removeFile

## [3.0.0-nullsafety.2] - 2021-03-22

* Fix sqflite warning

## [3.0.0-nullsafety.1] - 2021-03-02

* Bug fix for NonStoringObjectProvider.

## [3.0.0-nullsafety.0] - 2021-02-25

* Migration to nullsafety.

## [2.1.2] - 2021-03-09

* Update dependencies
* Bug fix for JsonCacheInfoRepository when file is corrupted.

## [2.1.1] - 2021-01-14

* Update minimal dependency sqflite
* Small fix for non-existing directory (PR [#264](https://github.com/Baseflow/flutter_cache_manager/pull/264))

## [2.1.0] - 2020-12-21

* Added ImageCacheManager with support for image resizing.
* Upgrade dependencies.

## [2.0.0] - 2020-10-16

* Restructured the configuration of the CacheManager. Look at the ReadMe for more information.
* Added queueing mechanism for downloading new files. By default, the cache manager downloads a maximum of 10 files
at the same time.
Expand All @@ -84,14 +110,15 @@ import 'package:flutter_cache_manager/file.dart' as cache_file;
* **BREAKING CHANGE** A CacheInfoRepository is now assumed to allow multiple connections, which means you can call
'open' multiple times and the repo keeps track on the number of connections.


## [2.0.0-beta.1] - 2020-10-10

* Reintroduced BaseCacheManager interface for backwards compatibility.
* Renamed putExistFile to putFileStream. This is equally efficient, but more clear in what it does.

## [2.0.0-beta] - 2020-10-01

* Added option for a key different from the url.
* Added a new CacheInfoRepository: JsonCacheInfoRepository, which is not used by default on the existing platforms,
* Added a new CacheInfoRepository: JsonCacheInfoRepository, which is not used by default on the existing platforms,
but can be used on any.
* Added support for Windows and Linux using the JsonCacheInfoRepository by default.
* Added support for adding an existing file.
Expand All @@ -101,49 +128,56 @@ but can be used on any.
* **BREAKING CHANGE** A CacheInfoRepository is now assumed to allow multiple connections, which means you can call
'open' multiple times and the repo keeps track on the number of connections.


## [1.4.2] - 2020-09-10

* Compatibility with Flutter version 1.22.

## [1.4.1] - 2020-06-14

* Bugfix: CacheManager returned a file that didn't exist when the file was removed by the OS (or any other external system)
while the app was active. This also prevented the CacheManager to redownload the file ([PR #190](https://github.com/Baseflow/flutter_cache_manager/pull/190)).

## [1.4.0] - 2020-06-04

* Allow cleaning of memory cache ([PR #183](https://github.com/Baseflow/flutter_cache_manager/pull/183)).
* Bugfix: Cleaning doesn't want to delete a file twice anymore ([PR #185](https://github.com/Baseflow/flutter_cache_manager/pull/185)).

## [1.3.0] - 2020-05-28

* Basic web support. (At least it downloads the file for you.)
* Support for the following mimetypes:
* application/vnd.android.package-archive (apk)
* audio/x-aac (aac)
* video/quicktime (mov)
* application/vnd.android.package-archive (apk)
* audio/x-aac (aac)
* video/quicktime (mov)

## [1.2.2] - 2020-04-16

* Support for RxDart 0.24.x

## [1.2.1] - 2020-04-14

* Fixed optional parameters in the Content-Type header ([#164](https://github.com/Baseflow/flutter_cache_manager/issues/164)).

## [1.2.0] - 2020-04-10

* Added getFileStream to CacheManager
* getFileStream has an optional parameter 'withProgress' to receive progress.
* getFileStream returns a FileResponse which is either a FileInfo or a DownloadProgress.
* getFileStream has an optional parameter 'withProgress' to receive progress.
* getFileStream returns a FileResponse which is either a FileInfo or a DownloadProgress.
* Changes to FileFetcher and FileFetcherResponse:
* FileFetcher is now replaced with a FileService which is a class instead of a function.
* FileServiceResponse doesn't just give magic headers, but concrete implementation of the needed information.
* FileServiceResponse gives a contentStream instead of content for more efficient handling of the data.
* FileServiceResponse contains contentLength with information about the total size of the content.
* FileFetcher is now replaced with a FileService which is a class instead of a function.
* FileServiceResponse doesn't just give magic headers, but concrete implementation of the needed information.
* FileServiceResponse gives a contentStream instead of content for more efficient handling of the data.
* FileServiceResponse contains contentLength with information about the total size of the content.
* Changes in CacheStore for testability:
* CleanupRunMinInterval can now be set.
* Expects a mockable directory instead of a path.
* CleanupRunMinInterval can now be set.
* Expects a mockable directory instead of a path.
* Added CacheInfoRepository interface to possibly replace the current CacheObjectProvider based on sqflite.
* Changes in WebHelper
* Files are now always saved with a new name. Files are first saved to storage before old file is removed.
* General code quality improvements

## [1.1.3] - 2019-10-17

* Use try-catch in WebHelper so VM understands that errors are not uncaught.

## [1.1.2] - 2019-10-16
Expand Down Expand Up @@ -203,7 +237,7 @@ while the app was active. This also prevented the CacheManager to redownload the

## [0.0.4+1] - 2018-02-16

* Fixed nullpointer when non-updated file (a 304 response) has no cache-control period.
* Fixed nullpointer when non-updated file (a 304 response) has no cache-control period.

## [0.0.4] - 2018-01-31

Expand Down
9 changes: 9 additions & 0 deletions flutter_cache_manager/lib/src/cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ class CacheManager implements BaseCacheManager {
if (cacheFile == null && streamController.hasListener) {
streamController.addError(e);
}

if (cacheFile != null &&
e is HttpExceptionWithStatus &&
e.statusCode == 404) {
if (streamController.hasListener) {
streamController.addError(e);
}
await removeFile(key);
}
}
}
streamController.close();
Expand Down
36 changes: 36 additions & 0 deletions flutter_cache_manager/test/cache_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,42 @@ void main() {
await expectLater(fileStream, emitsError(error));
verify(webHelper.downloadFile(any, key: anyNamed('key'))).called(1);
});

test(
'Outdated cacheFile should call to web, where 404 response should add Error to Stream and evict cache',
() async {
var fileName = 'test.jpg';
var fileUrl = 'baseflow.com/test';
var validTill = DateTime.now().subtract(const Duration(days: 1));

var store = MockCacheStore();
var file = await createTestConfig().fileSystem.createFile(fileName);
var cachedInfo = FileInfo(file, FileSource.Cache, validTill, fileUrl);
var cacheObject = CacheObject(fileUrl,
relativePath: file.path, validTill: validTill, id: 123);
when(store.getFile(fileUrl)).thenAnswer((_) => Future.value(cachedInfo));
when(store.retrieveCacheData(fileUrl))
.thenAnswer((_) => Future.value(cacheObject));

var webHelper = MockWebHelper();
var error = HttpExceptionWithStatus(404, 'Invalid statusCode: 404',
uri: Uri.parse(fileUrl));
when(webHelper.downloadFile(fileUrl, key: anyNamed('key')))
.thenThrow(error);

var cacheManager = TestCacheManager(
createTestConfig(),
store: store,
webHelper: webHelper,
);

// ignore: deprecated_member_use_from_same_package
var fileStream = cacheManager.getFile(fileUrl);
await expectLater(
fileStream, emitsInOrder([cachedInfo, emitsError(error)]));
verify(webHelper.downloadFile(any, key: anyNamed('key'))).called(1);
verify(store.removeCachedFile(cacheObject)).called(1);
});
});
group('explicit key', () {
test('Valid cacheFile should not call to web', () async {
Expand Down

0 comments on commit a1b4955

Please sign in to comment.