2020-04-24 20:47:21 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2020-05-04 20:44:34 +00:00
|
|
|
import 'package:photos/core/cache/lru_map.dart';
|
2020-05-01 18:20:12 +00:00
|
|
|
import 'package:photos/models/photo.dart';
|
2020-04-24 20:47:21 +00:00
|
|
|
|
|
|
|
class ThumbnailLruCache {
|
2020-04-25 10:28:22 +00:00
|
|
|
static LRUMap<_ThumbnailCacheKey, Uint8List> _map = LRUMap(5000);
|
2020-04-24 20:47:21 +00:00
|
|
|
|
2020-04-25 10:28:22 +00:00
|
|
|
static Uint8List get(Photo photo, int size) {
|
|
|
|
return _map.get(_ThumbnailCacheKey(photo, size));
|
2020-04-24 20:47:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 10:28:22 +00:00
|
|
|
static void put(Photo photo, int size, Uint8List imageData) {
|
|
|
|
_map.put(_ThumbnailCacheKey(photo, size), imageData);
|
2020-04-24 20:47:21 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-25 10:28:22 +00:00
|
|
|
|
|
|
|
class _ThumbnailCacheKey {
|
|
|
|
Photo photo;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
_ThumbnailCacheKey(this.photo, this.size);
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) =>
|
|
|
|
identical(this, other) ||
|
|
|
|
other is _ThumbnailCacheKey &&
|
|
|
|
runtimeType == other.runtimeType &&
|
|
|
|
photo.generatedId == other.photo.generatedId &&
|
|
|
|
size == other.size;
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode => photo.hashCode * size.hashCode;
|
|
|
|
}
|