UNPKG

@selfcommunity/utils

Version:

Utilities to integrate a Community.

91 lines (90 loc) 1.96 kB
/** * LruCache interface */ export interface LruCacheType<T> { get: (key: string, value?: T, options?: { noSsr: boolean; }) => T; set: (key: string, value: T, options?: { noSsr: boolean; }) => void; hasKey: (key: string) => boolean; delete: (key: string) => void; deleteKeys: (keys: string[]) => void; deleteKeysWithPrefix: (prefix: string) => void; clean: () => void; evaluate: () => void; } /** * LruCache */ export declare class LruCache<T> { private values; private maxEntries; private ssr; /** * Initialize Cache * @param maxEntries */ constructor(maxEntries?: number); /** * Get a key from the map store * @param key * @param value * @param options */ get(key: string, value?: T, options?: { noSsr: boolean; }): T; /** * Set a key in the store * @param key * @param value * @param options */ set(key: string, value: T, options?: { noSsr: boolean; }): void; /** * Check if key is in cache * @param key */ hasKey(key: string): boolean; /** * Delete a key in the store * @param key */ delete(key: string): void; /** * Delete all entry with prefix keys * @param keys */ deleteKeys(keys: string[]): void; /** * Delete all entry with prefix keys * @param prefix */ deleteKeysWithPrefix(prefix: string): void; /** * Clean the store */ clean(): void; /** * Print the store in the console * Only for debug */ evaluate(): void; } /** * Define the various types of caching strategies */ export declare enum CacheStrategies { CACHE_FIRST = "Cache-first", NETWORK_ONLY = "Network-only", STALE_WHILE_REVALIDATE = "Stale-While-Revalidate" } /** * Export global cache */ declare const cache: LruCacheType<any>; export default cache;