ente/lib/core/cache/thumbnail_cache.dart

35 lines
862 B
Dart
Raw Normal View History

import 'dart:typed_data';
2020-05-04 20:44:34 +00:00
import 'package:photos/core/cache/lru_map.dart';
2020-06-19 23:03:26 +00:00
import 'package:photos/models/file.dart';
class ThumbnailLruCache {
2020-06-12 16:53:23 +00:00
static LRUMap<_ThumbnailCacheKey, Uint8List> _map = LRUMap(1000);
2020-06-19 23:03:26 +00:00
static Uint8List get(File photo, int size) {
2020-04-25 10:28:22 +00:00
return _map.get(_ThumbnailCacheKey(photo, size));
}
2020-06-19 23:03:26 +00:00
static void put(File photo, int size, Uint8List imageData) {
2020-04-25 10:28:22 +00:00
_map.put(_ThumbnailCacheKey(photo, size), imageData);
}
}
2020-04-25 10:28:22 +00:00
class _ThumbnailCacheKey {
2020-06-19 23:03:26 +00:00
File photo;
2020-04-25 10:28:22 +00:00
int size;
_ThumbnailCacheKey(this.photo, this.size);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is _ThumbnailCacheKey &&
runtimeType == other.runtimeType &&
2020-06-06 12:07:24 +00:00
photo.hashCode == other.photo.hashCode &&
2020-04-25 10:28:22 +00:00
size == other.size;
@override
int get hashCode => photo.hashCode * size.hashCode;
}