mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31:59 +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: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_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
|
/// [ImageCache] that uses two caches for small and large images
|
||||||
/// so that a single large image does not evict all small iamges
|
/// so that a single large image does not evict all small iamges
|
||||||
|
@ -31,9 +32,18 @@ final class CustomImageCache implements ImageCache {
|
||||||
_large.clearLiveImages();
|
_large.clearLiveImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the cache for the given key
|
||||||
|
ImageCache _cacheForKey(Object key) =>
|
||||||
|
(key is ImmichLocalImageProvider || key is ImmichRemoteImageProvider)
|
||||||
|
? _large
|
||||||
|
: _small;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool containsKey(Object key) =>
|
bool containsKey(Object key) {
|
||||||
(key is ImmichLocalImageProvider ? _large : _small).containsKey(key);
|
// [ImmichLocalImageProvider] and [ImmichRemoteImageProvider] are both
|
||||||
|
// large size images while the other thumbnail providers are small
|
||||||
|
return _cacheForKey(key).containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get currentSize => _small.currentSize + _large.currentSize;
|
int get currentSize => _small.currentSize + _large.currentSize;
|
||||||
|
@ -43,8 +53,7 @@ final class CustomImageCache implements ImageCache {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool evict(Object key, {bool includeLive = true}) =>
|
bool evict(Object key, {bool includeLive = true}) =>
|
||||||
(key is ImmichLocalImageProvider ? _large : _small)
|
_cacheForKey(key).evict(key, includeLive: includeLive);
|
||||||
.evict(key, includeLive: includeLive);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get liveImageCount => _small.liveImageCount + _large.liveImageCount;
|
int get liveImageCount => _small.liveImageCount + _large.liveImageCount;
|
||||||
|
@ -59,10 +68,9 @@ final class CustomImageCache implements ImageCache {
|
||||||
ImageStreamCompleter Function() loader, {
|
ImageStreamCompleter Function() loader, {
|
||||||
ImageErrorListener? onError,
|
ImageErrorListener? onError,
|
||||||
}) =>
|
}) =>
|
||||||
(key is ImmichLocalImageProvider ? _large : _small)
|
_cacheForKey(key).putIfAbsent(key, loader, onError: onError);
|
||||||
.putIfAbsent(key, loader, onError: onError);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ImageCacheStatus statusForKey(Object key) =>
|
ImageCacheStatus statusForKey(Object key) =>
|
||||||
(key is ImmichLocalImageProvider ? _large : _small).statusForKey(key);
|
_cacheForKey(key).statusForKey(key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue