mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Add album list response caching
This commit is contained in:
38
mobile/lib/modules/album/services/album_cache.service.dart
Normal file
38
mobile/lib/modules/album/services/album_cache.service.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/constants/hive_box.dart';
|
||||
import 'package:immich_mobile/modules/home/services/asset_cache.service.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class AlbumCacheService extends JsonCache<List<AlbumResponseDto>> {
|
||||
AlbumCacheService() : super(albumListCacheBox, albumListCachedAssets);
|
||||
|
||||
@override
|
||||
void put(List<AlbumResponseDto> data) {
|
||||
putRawData(data.map((e) => e.toJson()).toList());
|
||||
}
|
||||
|
||||
@override
|
||||
List<AlbumResponseDto> get() {
|
||||
try {
|
||||
final mapList = readRawData() as List<dynamic>;
|
||||
|
||||
final responseData = mapList
|
||||
.map((e) => AlbumResponseDto.fromJson(e))
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
|
||||
return responseData;
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final albumCacheServiceProvider = Provider(
|
||||
(ref) => AlbumCacheService(),
|
||||
);
|
||||
Reference in New Issue
Block a user