Add in memory cache for thumbnails to improve hero experience
This commit is contained in:
parent
2505389d00
commit
a1ebee60b8
2 changed files with 18 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/core/cache/image_cache.dart';
|
||||
import 'package:photos/core/cache/thumbnail_cache.dart';
|
||||
import 'package:photos/file_repository.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
|
@ -119,6 +120,12 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
!_encounteredErrorLoadingThumbnail &&
|
||||
!_isLoadingThumbnail) {
|
||||
_isLoadingThumbnail = true;
|
||||
final cachedThumbnail = ThumbnailFileLruCache.get(widget.file);
|
||||
if (cachedThumbnail != null) {
|
||||
_imageProvider = Image.file(cachedThumbnail).image;
|
||||
_hasLoadedThumbnail = true;
|
||||
return;
|
||||
}
|
||||
getThumbnailFromServer(widget.file).then((file) {
|
||||
final imageProvider = Image.file(file).image;
|
||||
if (mounted) {
|
||||
|
|
|
@ -101,14 +101,23 @@ Future<io.File> getFileFromServer(File file) async {
|
|||
|
||||
Future<io.File> getThumbnailFromServer(File file) async {
|
||||
if (!file.isEncrypted) {
|
||||
return ThumbnailCacheManager().getSingleFile(file.getThumbnailUrl());
|
||||
return ThumbnailCacheManager()
|
||||
.getSingleFile(file.getThumbnailUrl())
|
||||
.then((data) {
|
||||
ThumbnailFileLruCache.put(file, data);
|
||||
return data;
|
||||
});
|
||||
} else {
|
||||
return ThumbnailCacheManager()
|
||||
.getFileFromCache(file.getThumbnailUrl())
|
||||
.then((info) {
|
||||
if (info == null) {
|
||||
return _downloadAndDecryptThumbnail(file);
|
||||
return _downloadAndDecryptThumbnail(file).then((data) {
|
||||
ThumbnailFileLruCache.put(file, data);
|
||||
return data;
|
||||
});
|
||||
} else {
|
||||
ThumbnailFileLruCache.put(file, info.file);
|
||||
return info.file;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue