improve image caching and disposal
This commit is contained in:
1 parent
e691a97159
commit
057d14b6d9
12 files changed
+69
-37
No files matched your search
@@ -29,6 +29,11 @@ final _cache = LRUCache<int, EquatableImage>(
|
||||
onEvict: (image) => image.dispose(),
|
||||
);
|
||||
|
||||
/// Clears the global image cache, disposing all cached images.
|
||||
void clearImageCache() {
|
||||
_cache.clear();
|
||||
}
|
||||
|
||||
Future<EquatableImage?> tryDecodeImage(
|
||||
Uint8List bytes, {
|
||||
int? targetWidth,
|
||||
@@ -38,8 +43,10 @@ Future<EquatableImage?> tryDecodeImage(
|
||||
final digest = secureHash(bytes);
|
||||
|
||||
final cached = _cache.get(digest);
|
||||
if (cached != null && !cached.isDisposed) {
|
||||
if (cached?.value != null) {
|
||||
return cached;
|
||||
} else if (cached != null) {
|
||||
_cache.remove(digest);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user