-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_service.dart
51 lines (39 loc) · 1.77 KB
/
cache_service.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import 'dart:async';
import 'package:dartlcemodel/dartlcemodel_cache.dart';
import './async_delegate_cache_service.dart';
/// Interface to cache an [Entity] locally
/// Cache should notify subscribers that data has been updated through [getData] channel
/// [D] Data type
/// [P] Params that identify data type
abstract class CacheService<D extends Object, P extends Object> {
/// Creates a [SyncCacheDelegate] cache service
/// [delegate] Delegate that synchronously performs caching actions
factory CacheService.withSyncDelegate(SyncCacheDelegate<D, P> delegate) {
return AsyncDelegateCacheService(AsyncCacheDelegate(delegate));
}
/// Creates a [AsyncCacheDelegate] cache service
/// [delegate] Delegate that synchronously performs caching actions
factory CacheService.withAsyncDelegate(AsyncCacheDelegate<D, P> delegate) = AsyncDelegateCacheService;
/// Subscribes to cache data updates.
/// Cache update listeners with new cached values.
/// [params] Params to notify of changes
Stream<Entity<D>?> getData(P params);
/// Saves entity in a cache
/// [params] Params that identify entity
/// [entity] Data to save
Future<void> save(P params, Entity<D> entity);
/// Makes cache service to refetch cached data updating subscribers with [params]
/// [params] Params that identify entity
Future<void> refetch(P params);
/// Makes cache service to refetch cached data for all active subscribers
Future<void> refetchAll();
/// Invalidates cached value
/// [params] Params that identify entity
Future<void> invalidate(P params);
/// Invalidates all cached values
Future<void> invalidateAll();
/// Deletes cached value.
/// The [getData] observable for the same key will emit `null`.
/// [params] Caching key
Future<void> delete(P params);
}