mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
JSON based caching
This commit is contained in:
parent
1156290377
commit
894eea739e
2 changed files with 33 additions and 59 deletions
|
|
@ -16,6 +16,10 @@ class AssetNotifier extends StateNotifier<List<AssetResponseDto>> {
|
|||
|
||||
AssetNotifier(this._assetService, this._assetCacheService) : super([]);
|
||||
|
||||
_cacheState() {
|
||||
_assetCacheService.putAssets(state);
|
||||
}
|
||||
|
||||
getAllAsset() async {
|
||||
if (_assetCacheService.isValid() && state.isEmpty) {
|
||||
state = await _assetCacheService.getAssetsAsync();
|
||||
|
|
@ -25,16 +29,18 @@ class AssetNotifier extends StateNotifier<List<AssetResponseDto>> {
|
|||
|
||||
if (allAssets != null) {
|
||||
state = allAssets;
|
||||
_assetCacheService.putAssets(allAssets);
|
||||
_cacheState();
|
||||
}
|
||||
}
|
||||
|
||||
clearAllAsset() {
|
||||
state = [];
|
||||
_cacheState();
|
||||
}
|
||||
|
||||
onNewAssetUploaded(AssetResponseDto newAsset) {
|
||||
state = [...state, newAsset];
|
||||
_cacheState();
|
||||
}
|
||||
|
||||
deleteAssets(Set<AssetResponseDto> deleteAssets) async {
|
||||
|
|
@ -73,6 +79,8 @@ class AssetNotifier extends StateNotifier<List<AssetResponseDto>> {
|
|||
state.where((immichAsset) => immichAsset.id != asset.id).toList();
|
||||
}
|
||||
}
|
||||
|
||||
_cacheState();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue