ente/lib/core/thumbnail_cache.dart

35 lines
866 B
Dart
Raw Normal View History

import 'dart:typed_data';
import 'package:photos/core/lru_map.dart';
2020-05-01 18:20:12 +00:00
import 'package:photos/models/photo.dart';
class ThumbnailLruCache {
2020-04-25 10:28:22 +00:00
static LRUMap<_ThumbnailCacheKey, Uint8List> _map = LRUMap(5000);
2020-04-25 10:28:22 +00:00
static Uint8List get(Photo photo, int size) {
return _map.get(_ThumbnailCacheKey(photo, size));
}
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-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;
}