Skip to content

Commit a1b4955

Browse files
committed
Merge branch 'develop-evict' into develop
2 parents c3fce5b + 2a79666 commit a1b4955

File tree

3 files changed

+94
-15
lines changed

3 files changed

+94
-15
lines changed

flutter_cache_manager/CHANGELOG.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,102 @@
1+
## [3.3.4] - 2023-12-05
2+
3+
* [Bugfix] For a previously cached file that got removed on the server, now evicts that file on 404 and notifies listeners.
4+
15
## [3.3.3] - 2024-07-23
6+
27
* Updates dependencies ([#457](https://github.com/Baseflow/flutter_cache_manager/pull/457))
38

49
## [3.3.2] - 2024-04-25
10+
511
* Updates dependencies to their latest versions.
612

713
## [3.3.1] - 2023-07-03
14+
815
* Support Dart 3.0.0 for http ^1.0.0 and file ^7.0.0
916
* Update example
1017
* Add topics
1118

1219
## [3.3.0] - 2021-11-29
20+
1321
* Added option to manage the log level. Doesn't print failed downloads by default anymore. You can set it like this:
22+
1423
```dart
1524
CacheManager.logLevel = CacheManagerLogLevel.verbose;
1625
```
1726

1827
## [3.2.0] - 2021-11-27
28+
1929
* [Bugfix] getSingleFile now downloads a new file before completing as the outdated file might have been deleted.
2030

2131
## [3.1.3] - 2021-11-05
32+
2233
* Disabled resizing of cached gifs as this was broken.
2334

2435
## [3.1.2] - 2021-06-17
36+
2537
* removeFile function now completes after the file is removed from disk and not earlier ([#323](https://github.com/Baseflow/flutter_cache_manager/pull/323))
2638
* 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))
2739

2840
## [3.1.1] - 2021-06-03
41+
2942
* Move File to separate file. You can add it using the following import:
43+
3044
```dart
3145
import 'package:flutter_cache_manager/file.dart' as cache_file;
3246
```
3347

3448
## [3.1.0] - 2021-05-28
49+
3550
* Export File from package file ([#302](https://github.com/Baseflow/flutter_cache_manager/pull/302))
3651
* Bugfix for eTag on Flutter Web ([#304](https://github.com/Baseflow/flutter_cache_manager/pull/315))
3752
* Bugfix for loading multiple images simultaneously ([#315](https://github.com/Baseflow/flutter_cache_manager/pull/315))
3853

3954
## [3.0.2] - 2021-05-10
55+
4056
* Include rxdart 0.27 as possible dependency
4157

4258
## [3.0.1] - 2021-03-29
59+
4360
* Include file 6.0.0 as possible dependency
4461

4562
## [3.0.0] - 2021-03-27
63+
4664
* Bug fix on removing a relatively new file from cache
4765
* Migration to nullsafety.
4866

4967
## [3.0.0-nullsafety.3] - 2021-03-26
68+
5069
* Add null-check on id in removeFile
5170

5271
## [3.0.0-nullsafety.2] - 2021-03-22
72+
5373
* Fix sqflite warning
5474

5575
## [3.0.0-nullsafety.1] - 2021-03-02
76+
5677
* Bug fix for NonStoringObjectProvider.
5778

5879
## [3.0.0-nullsafety.0] - 2021-02-25
80+
5981
* Migration to nullsafety.
6082

6183
## [2.1.2] - 2021-03-09
84+
6285
* Update dependencies
6386
* Bug fix for JsonCacheInfoRepository when file is corrupted.
6487

6588
## [2.1.1] - 2021-01-14
89+
6690
* Update minimal dependency sqflite
6791
* Small fix for non-existing directory (PR [#264](https://github.com/Baseflow/flutter_cache_manager/pull/264))
6892

6993
## [2.1.0] - 2020-12-21
94+
7095
* Added ImageCacheManager with support for image resizing.
7196
* Upgrade dependencies.
7297

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

87-
88113
## [2.0.0-beta.1] - 2020-10-10
114+
89115
* Reintroduced BaseCacheManager interface for backwards compatibility.
90116
* Renamed putExistFile to putFileStream. This is equally efficient, but more clear in what it does.
91117

92118
## [2.0.0-beta] - 2020-10-01
119+
93120
* Added option for a key different from the url.
94-
* Added a new CacheInfoRepository: JsonCacheInfoRepository, which is not used by default on the existing platforms,
121+
* Added a new CacheInfoRepository: JsonCacheInfoRepository, which is not used by default on the existing platforms,
95122
but can be used on any.
96123
* Added support for Windows and Linux using the JsonCacheInfoRepository by default.
97124
* Added support for adding an existing file.
@@ -101,49 +128,56 @@ but can be used on any.
101128
* **BREAKING CHANGE** A CacheInfoRepository is now assumed to allow multiple connections, which means you can call
102129
'open' multiple times and the repo keeps track on the number of connections.
103130

104-
105131
## [1.4.2] - 2020-09-10
132+
106133
* Compatibility with Flutter version 1.22.
107134

108135
## [1.4.1] - 2020-06-14
136+
109137
* Bugfix: CacheManager returned a file that didn't exist when the file was removed by the OS (or any other external system)
110138
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)).
111139

112140
## [1.4.0] - 2020-06-04
141+
113142
* Allow cleaning of memory cache ([PR #183](https://github.com/Baseflow/flutter_cache_manager/pull/183)).
114143
* Bugfix: Cleaning doesn't want to delete a file twice anymore ([PR #185](https://github.com/Baseflow/flutter_cache_manager/pull/185)).
115144

116145
## [1.3.0] - 2020-05-28
146+
117147
* Basic web support. (At least it downloads the file for you.)
118148
* Support for the following mimetypes:
119-
* application/vnd.android.package-archive (apk)
120-
* audio/x-aac (aac)
121-
* video/quicktime (mov)
149+
* application/vnd.android.package-archive (apk)
150+
* audio/x-aac (aac)
151+
* video/quicktime (mov)
122152

123153
## [1.2.2] - 2020-04-16
154+
124155
* Support for RxDart 0.24.x
125156

126157
## [1.2.1] - 2020-04-14
158+
127159
* Fixed optional parameters in the Content-Type header ([#164](https://github.com/Baseflow/flutter_cache_manager/issues/164)).
128160

129161
## [1.2.0] - 2020-04-10
162+
130163
* Added getFileStream to CacheManager
131-
* getFileStream has an optional parameter 'withProgress' to receive progress.
132-
* getFileStream returns a FileResponse which is either a FileInfo or a DownloadProgress.
164+
* getFileStream has an optional parameter 'withProgress' to receive progress.
165+
* getFileStream returns a FileResponse which is either a FileInfo or a DownloadProgress.
133166
* Changes to FileFetcher and FileFetcherResponse:
134-
* FileFetcher is now replaced with a FileService which is a class instead of a function.
135-
* FileServiceResponse doesn't just give magic headers, but concrete implementation of the needed information.
136-
* FileServiceResponse gives a contentStream instead of content for more efficient handling of the data.
137-
* FileServiceResponse contains contentLength with information about the total size of the content.
167+
* FileFetcher is now replaced with a FileService which is a class instead of a function.
168+
* FileServiceResponse doesn't just give magic headers, but concrete implementation of the needed information.
169+
* FileServiceResponse gives a contentStream instead of content for more efficient handling of the data.
170+
* FileServiceResponse contains contentLength with information about the total size of the content.
138171
* Changes in CacheStore for testability:
139-
* CleanupRunMinInterval can now be set.
140-
* Expects a mockable directory instead of a path.
172+
* CleanupRunMinInterval can now be set.
173+
* Expects a mockable directory instead of a path.
141174
* Added CacheInfoRepository interface to possibly replace the current CacheObjectProvider based on sqflite.
142175
* Changes in WebHelper
143176
* Files are now always saved with a new name. Files are first saved to storage before old file is removed.
144177
* General code quality improvements
145178

146179
## [1.1.3] - 2019-10-17
180+
147181
* Use try-catch in WebHelper so VM understands that errors are not uncaught.
148182

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

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

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

208242
## [0.0.4] - 2018-01-31
209243

flutter_cache_manager/lib/src/cache_manager.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ class CacheManager implements BaseCacheManager {
154154
if (cacheFile == null && streamController.hasListener) {
155155
streamController.addError(e);
156156
}
157+
158+
if (cacheFile != null &&
159+
e is HttpExceptionWithStatus &&
160+
e.statusCode == 404) {
161+
if (streamController.hasListener) {
162+
streamController.addError(e);
163+
}
164+
await removeFile(key);
165+
}
157166
}
158167
}
159168
streamController.close();

flutter_cache_manager/test/cache_manager_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,42 @@ void main() {
215215
await expectLater(fileStream, emitsError(error));
216216
verify(webHelper.downloadFile(any, key: anyNamed('key'))).called(1);
217217
});
218+
219+
test(
220+
'Outdated cacheFile should call to web, where 404 response should add Error to Stream and evict cache',
221+
() async {
222+
var fileName = 'test.jpg';
223+
var fileUrl = 'baseflow.com/test';
224+
var validTill = DateTime.now().subtract(const Duration(days: 1));
225+
226+
var store = MockCacheStore();
227+
var file = await createTestConfig().fileSystem.createFile(fileName);
228+
var cachedInfo = FileInfo(file, FileSource.Cache, validTill, fileUrl);
229+
var cacheObject = CacheObject(fileUrl,
230+
relativePath: file.path, validTill: validTill, id: 123);
231+
when(store.getFile(fileUrl)).thenAnswer((_) => Future.value(cachedInfo));
232+
when(store.retrieveCacheData(fileUrl))
233+
.thenAnswer((_) => Future.value(cacheObject));
234+
235+
var webHelper = MockWebHelper();
236+
var error = HttpExceptionWithStatus(404, 'Invalid statusCode: 404',
237+
uri: Uri.parse(fileUrl));
238+
when(webHelper.downloadFile(fileUrl, key: anyNamed('key')))
239+
.thenThrow(error);
240+
241+
var cacheManager = TestCacheManager(
242+
createTestConfig(),
243+
store: store,
244+
webHelper: webHelper,
245+
);
246+
247+
// ignore: deprecated_member_use_from_same_package
248+
var fileStream = cacheManager.getFile(fileUrl);
249+
await expectLater(
250+
fileStream, emitsInOrder([cachedInfo, emitsError(error)]));
251+
verify(webHelper.downloadFile(any, key: anyNamed('key'))).called(1);
252+
verify(store.removeCachedFile(cacheObject)).called(1);
253+
});
218254
});
219255
group('explicit key', () {
220256
test('Valid cacheFile should not call to web', () async {

0 commit comments

Comments
 (0)