evictFromCache static method
Future<bool>
evictFromCache(
- String url, {
- String? cacheKey,
- BaseCacheManager? cacheManager,
- double scale = 1,
- Duration minimumGifFrameDuration = const Duration(milliseconds: 100),
Evict an image from both the disk file based caching system of the
BaseCacheManager as the in memory ImageCache of the ImageProvider.
url is used by both the disk and memory cache. The cacheKey and
scale are only used to clear the image from the ImageCache, and must
match the ones the widget was rendered with.
animate is part of the provider key too, but the caller is not expected to know which value the widget used, so both variants are evicted.
Implementation
static Future<bool> evictFromCache(
String url, {
String? cacheKey,
BaseCacheManager? cacheManager,
double scale = 1,
Duration minimumGifFrameDuration = const Duration(milliseconds: 100),
}) async {
final effectiveCacheManager = _effectiveCacheManager(cacheManager);
await effectiveCacheManager.removeFile(cacheKey ?? url);
var evicted = false;
for (final animate in const [true, false]) {
final wasCached = await CachedNetworkImageProvider(
url,
cacheKey: cacheKey,
scale: scale,
minimumGifFrameDuration: minimumGifFrameDuration,
animate: animate,
).evict();
evicted = evicted || wasCached;
}
return evicted;
}