mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
fix(mobile): Fixes large and small image cache (#7726)
Fixes large and small image cache
This commit is contained in:
parent
7a7475ed67
commit
21caa06fa2
1 changed files with 15 additions and 7 deletions
22
mobile/lib/shared/cache/custom_image_cache.dart
vendored
22
mobile/lib/shared/cache/custom_image_cache.dart
vendored
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/painting.dart';
|
||||
import 'package:immich_mobile/modules/asset_viewer/image_providers/immich_local_image_provider.dart';
|
||||
import 'package:immich_mobile/modules/asset_viewer/image_providers/immich_remote_image_provider.dart';
|
||||
|
||||
/// [ImageCache] that uses two caches for small and large images
|
||||
/// so that a single large image does not evict all small iamges
|
||||
|
@ -31,9 +32,18 @@ final class CustomImageCache implements ImageCache {
|
|||
_large.clearLiveImages();
|
||||
}
|
||||
|
||||
/// Gets the cache for the given key
|
||||
ImageCache _cacheForKey(Object key) =>
|
||||
(key is ImmichLocalImageProvider || key is ImmichRemoteImageProvider)
|
||||
? _large
|
||||
: _small;
|
||||
|
||||
@override
|
||||
bool containsKey(Object key) =>
|
||||
(key is ImmichLocalImageProvider ? _large : _small).containsKey(key);
|
||||
bool containsKey(Object key) {
|
||||
// [ImmichLocalImageProvider] and [ImmichRemoteImageProvider] are both
|
||||
// large size images while the other thumbnail providers are small
|
||||
return _cacheForKey(key).containsKey(key);
|
||||
}
|
||||
|
||||
@override
|
||||
int get currentSize => _small.currentSize + _large.currentSize;
|
||||
|
@ -43,8 +53,7 @@ final class CustomImageCache implements ImageCache {
|
|||
|
||||
@override
|
||||
bool evict(Object key, {bool includeLive = true}) =>
|
||||
(key is ImmichLocalImageProvider ? _large : _small)
|
||||
.evict(key, includeLive: includeLive);
|
||||
_cacheForKey(key).evict(key, includeLive: includeLive);
|
||||
|
||||
@override
|
||||
int get liveImageCount => _small.liveImageCount + _large.liveImageCount;
|
||||
|
@ -59,10 +68,9 @@ final class CustomImageCache implements ImageCache {
|
|||
ImageStreamCompleter Function() loader, {
|
||||
ImageErrorListener? onError,
|
||||
}) =>
|
||||
(key is ImmichLocalImageProvider ? _large : _small)
|
||||
.putIfAbsent(key, loader, onError: onError);
|
||||
_cacheForKey(key).putIfAbsent(key, loader, onError: onError);
|
||||
|
||||
@override
|
||||
ImageCacheStatus statusForKey(Object key) =>
|
||||
(key is ImmichLocalImageProvider ? _large : _small).statusForKey(key);
|
||||
_cacheForKey(key).statusForKey(key);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue