feat(ADM-018): completed feature
This commit is contained in:
20
project/src/modules/cache/domain/cache.ts
vendored
Normal file
20
project/src/modules/cache/domain/cache.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
export interface CacheEntry<T> {
|
||||
key: string;
|
||||
value: T;
|
||||
expiresAt: number;
|
||||
}
|
||||
|
||||
export interface CacheContract {
|
||||
name: string;
|
||||
keyPattern: string;
|
||||
ttlSeconds: number;
|
||||
sourceOfTruth: string;
|
||||
invalidation: string;
|
||||
}
|
||||
|
||||
export interface CacheMetrics {
|
||||
hits: number;
|
||||
misses: number;
|
||||
invalidations: number;
|
||||
hitRatio(): number;
|
||||
}
|
||||
21
project/src/modules/cache/domain/ports.ts
vendored
Normal file
21
project/src/modules/cache/domain/ports.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
export interface CacheAdapter {
|
||||
get<T>(key: string): Promise<T | undefined>;
|
||||
set<T>(key: string, value: T, ttlSeconds: number): Promise<void>;
|
||||
invalidate(key: string): Promise<void>;
|
||||
}
|
||||
|
||||
export interface CacheReadThrough {
|
||||
read<T>(contractName: string, key: string, loader: () => Promise<T>): Promise<T>;
|
||||
}
|
||||
|
||||
export interface CacheService extends CacheReadThrough {
|
||||
listContracts(): Array<{
|
||||
name: string;
|
||||
keyPattern: string;
|
||||
ttlSeconds: number;
|
||||
sourceOfTruth: string;
|
||||
invalidation: string;
|
||||
}>;
|
||||
invalidateByName(name: string): Promise<number>;
|
||||
metrics(): { hits: number; misses: number; invalidations: number; hitRatio: number };
|
||||
}
|
||||
Reference in New Issue
Block a user