-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacheProvider.ts
31 lines (28 loc) · 1.02 KB
/
cacheProvider.ts
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
export type CacheLoader<K, V> = (key: K) => Promise<V>;
export interface CacheProvider<K, V> {
/**
* Gets the cached value for the given key.
*
* If there is no cached value, a fresh value is retrieved from the given `loader` function.
*
* @param {K} key The key associated with the value to retrieve from the cache.
* @param {CacheLoader<K, V>} loader A function to load a fresh value.
* @returns {Promise<V>} A promise that resolves to the latest cached value.
*/
get(key: K, loader: CacheLoader<K, V>): Promise<V>;
/**
* Removes the value for the given key from the cache.
*
* @param {K} key The key associated with the value to remove from the cache.
* @returns {Promise<void>}
*/
delete(key: K): Promise<void>;
/**
* Sets the value for the given key.
*
* @param {K} key The key associated with the value to remove from the cache.
* @param {V} value
* @returns {Promise<void>}
*/
set(key: K, value: V): Promise<void>;
}