Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached file should be removed on 404, and error should be added to Stream even if a cached file exists #436

Open
ltOgt opened this issue Dec 5, 2023 · 0 comments

Comments

@ltOgt
Copy link

ltOgt commented Dec 5, 2023

馃悰 Bug Report

Moving Baseflow/flutter_cached_network_image#898 to here.

if (cacheFile == null || cacheFile.validTill.isBefore(DateTime.now())) {
try {
await for (final response
in _webHelper.downloadFile(url, key: key, authHeaders: headers)) {
if (response is DownloadProgress && withProgress) {
streamController.add(response);
}
if (response is FileInfo) {
streamController.add(response);
}
}
} on Object catch (e) {
cacheLogger.log(
'CacheManager: Failed to download file from $url with error:\n$e',
CacheManagerLogLevel.debug);
if (cacheFile == null && streamController.hasListener) {
streamController.addError(e);
}
}
}
streamController.close();

Currently, in CacheManager._pushFileToStream when a cacheFile exists, the cached content is emitted, and if it is outdated, a network request is made to potentially update the file, and emit the updated content.

If a 404 happens on that request, the error is not added to the stream, and the cache is not evicted.

The error is only added if no cacheFile exists.

Expected behavior

On the 404, the cache is evicted (the server is telling us the resource no longer exists) and the error is added to the stream.

Reproduction steps

See Baseflow/flutter_cached_network_image#898

Configuration

Version: 3.1.1

Platform:
Tested on macos but should affect all platforms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant