Baseflow / Baseflow/flutter_cached_network_image

Multiple issues for changed image behind unchanged URL, e.g. profile pictures / user avatars

Open
#897 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

There are quite a few issues about the use case of changing images behind an identical URL.

E.g. user profile pictures that have been changed by the user.

- https://github.com/Baseflow/flutter_cached_network_image/issues/768
- https://github.com/Baseflow/flutter_cached_network_image/issues/352
- https://github.com/Baseflow/flutter_cached_network_image/issues/650
- probably some more

The main issue here is that `ImageProvider.resolveStreamForKey` only calls `ImageProvider.loadImage` through `ImageCache.putIfAbsent`.

This means that all the good caching logic with `if-none-match` etc is only called once during the apps lifetime, when the URL is used for the first time and is not yet registered in `ImageCache`.

The quick solution here is to manually call
```dart
PaintingBinding.instance.imageCache.evict(CachedNetworkImageProvider(url), includeLive: true)
```
iff you know the exact url, or
```dart
PaintingBinding.instance.imageCache.clearLiveImages();
PaintingBinding.instance.imageCache.clear();
```
to brute-force clear the entire cache to force a refresh.
____

The package already exposes `CachedNetworkImage.evictFromCache(url)`, but this removes the on disk cache as well, meaning we don't get to use the old image while loading the new one, or checking with etag in case the resource has not changed after all.

It might be good to expose something like `CachedNetworkImage.forceRefresh(url)`.

_____
P.S. see https://github.com/ltOgt/flutter_cached_network_image_404 for a minimal example of this

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.