Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
738 stars 427 forks source link

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

Open ltOgt opened 7 months ago

ltOgt commented 7 months ago

🐛 Bug Report

Moving https://github.com/Baseflow/flutter_cached_network_image/issues/898 to here.

https://github.com/Baseflow/flutter_cache_manager/blob/32b71c1da1689b97434959ac407b03b74d7e405c/flutter_cache_manager/lib/src/cache_manager.dart#L137-L157

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 https://github.com/Baseflow/flutter_cached_network_image/issues/898

Configuration

Version: 3.1.1

Platform: Tested on macos but should affect all platforms