|
1 | 1 | import type { AsyncIterator } from 'asynciterator'; |
2 | 2 |
|
3 | | -export interface IPersistentCache<T> { |
4 | | - get: (key: string) => Promise<T | undefined>; |
5 | | - getMany: (keys: string[]) => Promise<(T | undefined)[]>; |
6 | | - set: (key: string, value: T) => Promise<void>; |
| 3 | +/** |
| 4 | + * Interface for a cache entry, allows the cache to output (O) different data |
| 5 | + * from what it being put into the cache (I). |
| 6 | + */ |
| 7 | +export interface IPersistentCache<S, O> { |
| 8 | + get: (key: string) => Promise<O | undefined>; |
| 9 | + getMany: (keys: string[]) => Promise<(O | undefined)[]>; |
| 10 | + set: (key: string, value: S) => Promise<void>; |
7 | 11 | has: (key: string) => Promise<boolean>; |
8 | 12 | delete: (key: string) => Promise<boolean>; |
9 | | - entries: () => AsyncIterator<[string, T]>; |
| 13 | + entries: () => AsyncIterator<[string, O]>; |
10 | 14 | size: () => Promise<number>; |
11 | 15 | serialize: () => Promise<void>; |
12 | 16 | /** |
@@ -48,36 +52,40 @@ export interface ICacheMetrics { |
48 | 52 | * tracking period |
49 | 53 | */ |
50 | 54 | evictionPercentage: number; |
| 55 | + /** |
| 56 | + * Additional metrics not covered by the base class |
| 57 | + */ |
| 58 | + additionalMetrics?: Record<string, any>; |
51 | 59 | } |
52 | 60 | /** |
53 | 61 | * Interface of class that sets a value in a given cache for a given key. This can |
54 | 62 | * be a simple URL -> ISourceState mapping or URL -> Source Data Summary. The |
55 | 63 | * computation and logic of what to store is done in the setInCache function. |
56 | | - * T = The type of data being stored (e.g., ISourceState) |
| 64 | + * I = The type of data being stored (e.g., ISourceState) |
57 | 65 | * C = The context needed to derive additional storage logic |
58 | 66 | */ |
59 | 67 | export interface ISetFn<I, S, C> { |
60 | 68 | setInCache: ( |
61 | 69 | key: string, |
62 | 70 | value: I, |
63 | | - cache: IPersistentCache<S>, |
| 71 | + cache: IPersistentCache<S, any>, |
64 | 72 | context: C |
65 | 73 | ) => Promise<void>; |
66 | 74 | } |
67 | 75 |
|
68 | | -export interface ICacheRegistryEntry<I, S, C> { |
69 | | - cache: IPersistentCache<S>; |
| 76 | +export interface ICacheRegistryEntry<I, S, O, C> { |
| 77 | + cache: IPersistentCache<S, O>; |
70 | 78 | setFn: ISetFn<I, S, C>; |
71 | 79 | } |
72 | 80 |
|
73 | 81 | /** |
74 | 82 | * Interface for a class that returns a view over the cache. This can be |
75 | 83 | * just retrieving a key, a summary of the content of the cache, or |
76 | 84 | * the content of a cache matching a certain operator (e.g. triple pattern). |
77 | | - * T the output type of the constructed view |
| 85 | + * I the output type of the constructed view |
78 | 86 | * C the context needed to construct the view |
79 | 87 | */ |
80 | | -export interface ICacheView<S, C, K> { |
81 | | - construct: (cache: IPersistentCache<S>, context: C) => Promise<K | undefined>; |
| 88 | +export interface ICacheView<S, O, C, K> { |
| 89 | + construct: (cache: IPersistentCache<S, O>, context: C) => Promise<K | undefined>; |
82 | 90 | } |
83 | 91 |
|
0 commit comments