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';
|
2021-05-06 22:35:56 +00:00
|
|
|
import 'package:photos/core/constants.dart';
|
2022-07-19 06:39:45 +00:00
|
|
|
import 'package:photos/models/ente_file.dart';
|
2020-04-24 20:47:21 +00:00
|
|
|
|
|
|
|
class ThumbnailLruCache {
|
2022-09-23 08:05:12 +00:00
|
|
|
static final LRUMap<String, Uint8List?> _map = LRUMap(1000);
|
2020-04-24 20:47:21 +00:00
|
|
|
|
2022-09-23 08:05:12 +00:00
|
|
|
static Uint8List? get(EnteFile enteFile, [int? size]) {
|
2022-06-11 08:23:52 +00:00
|
|
|
return _map.get(
|
2022-07-19 11:15:26 +00:00
|
|
|
enteFile.cacheKey() +
|
2022-06-11 08:23:52 +00:00
|
|
|
"_" +
|
2022-09-20 11:53:32 +00:00
|
|
|
(size != null ? size.toString() : thumbnailLargeSize.toString()),
|
2022-06-11 08:23:52 +00:00
|
|
|
);
|
2020-04-24 20:47:21 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 22:35:56 +00:00
|
|
|
static void put(
|
2022-07-19 11:15:26 +00:00
|
|
|
EnteFile enteFile,
|
2022-09-23 08:05:12 +00:00
|
|
|
Uint8List? imageData, [
|
|
|
|
int? size,
|
2021-05-06 22:35:56 +00:00
|
|
|
]) {
|
|
|
|
_map.put(
|
2022-07-19 11:15:26 +00:00
|
|
|
enteFile.cacheKey() +
|
2022-06-11 08:23:52 +00:00
|
|
|
"_" +
|
2022-09-20 11:53:32 +00:00
|
|
|
(size != null ? size.toString() : thumbnailLargeSize.toString()),
|
2022-06-11 08:23:52 +00:00
|
|
|
imageData,
|
|
|
|
);
|
2020-04-24 20:47:21 +00:00
|
|
|
}
|
2022-05-13 14:14:24 +00:00
|
|
|
|
2022-07-19 11:15:26 +00:00
|
|
|
static void clearCache(EnteFile enteFile) {
|
2022-05-13 14:14:24 +00:00
|
|
|
_map.remove(
|
2022-09-20 11:53:32 +00:00
|
|
|
enteFile.cacheKey() + "_" + thumbnailLargeSize.toString(),
|
2022-06-11 08:23:52 +00:00
|
|
|
);
|
2022-05-13 14:14:24 +00:00
|
|
|
_map.remove(
|
2022-09-20 11:53:32 +00:00
|
|
|
enteFile.cacheKey() + "_" + thumbnailSmallSize.toString(),
|
2022-06-11 08:23:52 +00:00
|
|
|
);
|
2022-05-13 14:14:24 +00:00
|
|
|
}
|
2020-04-24 20:47:21 +00:00
|
|
|
}
|