Switch to a global cache

This commit is contained in:
Vishnu Mohandas 2020-08-13 06:37:44 +05:30
parent d36b88aa23
commit fa53398887
2 changed files with 4 additions and 27 deletions

View file

@ -1,5 +1,4 @@
import 'dart:io' as dart;
import 'dart:typed_data';
import 'package:photos/core/cache/lru_map.dart';
import 'package:photos/models/file.dart';
@ -27,15 +26,3 @@ class ThumbnailFileLruCache {
_map.put(file.tag(), imageData);
}
}
class BytesLruCache {
static LRUMap<String, Uint8List> _map = LRUMap(25);
static Uint8List get(File file) {
return _map.get(file.tag());
}
static void put(File file, Uint8List imageData) {
_map.put(file.tag(), imageData);
}
}

View file

@ -94,24 +94,14 @@ class _ZoomableImageState extends State<ZoomableImage>
_loadedSmallThumbnail = true;
}
if (!_loadedFinalImage) {
if (BytesLruCache.get(_photo) != null) {
DefaultCacheManager().getSingleFile(_photo.getDownloadUrl()).then((file) {
_onFinalImageLoaded(
Image.memory(
BytesLruCache.get(_photo),
Image.file(
file,
gaplessPlayback: true,
).image,
context);
} else {
_photo.getBytes().then((data) {
_onFinalImageLoaded(
Image.memory(
data,
gaplessPlayback: true,
).image,
context);
BytesLruCache.put(_photo, data);
});
}
});
}
}