ente/lib/core/cache/thumbnail_cache.dart
2020-06-12 22:23:23 +05:30

35 lines
866 B
Dart

import 'dart:typed_data';
import 'package:photos/core/cache/lru_map.dart';
import 'package:photos/models/photo.dart';
class ThumbnailLruCache {
static LRUMap<_ThumbnailCacheKey, Uint8List> _map = LRUMap(1000);
static Uint8List get(Photo photo, int size) {
return _map.get(_ThumbnailCacheKey(photo, size));
}
static void put(Photo photo, int size, Uint8List imageData) {
_map.put(_ThumbnailCacheKey(photo, size), imageData);
}
}
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.hashCode == other.photo.hashCode &&
size == other.size;
@override
int get hashCode => photo.hashCode * size.hashCode;
}