export interface CacheEntry { key: string; cachedAt: number; usedAt: number; expiresAt: number; lastFetched: number; value: T; } export interface CacheFetcher { (skip: Function): Promise; } export interface FetchOptions { /** * The time to live to set for a fulfilled item */ timeToLive?: number; /** * What kind of cache miss strategy should be used here. * - "fulfill": * If the cache misses for any reason, wait until the new value is fetched and return it * - "fallback-refresh": * If the cache misses */ missStrategy?: "fulfill" | "fallback-refresh"; } export interface CacheSettings { /** * Default time that a cached item should be considered valid before expiring, in milliseconds */ timeToLive: number; /** * Amount of items that can be held in the cache maximum. */ maxItems: number; evictionStrategy?: 'age' | 'lru'; /** * When true (default), objects returned from cache APIs are deep-copied, and thus distinct from the * actual data stored in the cache. */ deepCopy?: boolean; } export declare class Cache { readonly name: string; readonly settings: CacheSettings; /** * */ constructor(name: string, settings: CacheSettings); protected entries: Map>; getInternalEntries(): Map>; clear(): void; delete(key: string): void; static getSharedCachesEnabled(): boolean; static setSharedCachesEnabled(enabled: any): void; /** * Immediately clear the contents of all shared caches */ static clearShared(timestamp?: any): void; /** * Get a cache shared by all end users when used in SSR (CAUTION). On the client side, it gets a cache * shared globally within the browser tab (in memory). * @param name * @param timeToLive * @param maxItems * @returns */ static shared(name: string, settings: CacheSettings): Cache; /** * Cache cleanup routine run whenever a value is stored in the cache */ private sliceCleanup; getItem(key: string): CacheEntry; getEvictionCandidate(): CacheEntry; getLeastRecentlyUsedEntry(): CacheEntry; getOldestEntry(): CacheEntry; /** * Insert an item into the cache with the given time to live. If not provided, the default is used. * @param key * @param value * @param timeToLive */ insertItem(key: string, value: T, timeToLive?: number): void; private fetchesInProgress; /** * Get the value of the given key, but if it is not present in the cache or is expired, execute the * provided fetcher function to fill the cache. * * @param key * @param fetcher * @param options * @returns */ fetch(key: string, fetcher?: CacheFetcher, options?: FetchOptions): Promise; /** * Get the value of an unexpired cache entry for the given key. * @param key * @returns */ get(key: string): T; /** * Internal implementation of the fetch() routine. * @param key * @param fetcher * @param options * @returns */ private fetchImmediate; }