/** * Cache class allowing to create caches with automatic cache loading and delegates. */ export declare abstract class BaseCacheLoader { private readonly cacheDefinition; private readonly cacheOptions; private delegate; private mode; protected isCacheable: boolean; /** * Constructor. * * @param {String} cacheId the identifier of the cache * @param {Object} cacheOptions the cache options: * * {Number} expirationTime: cache entries expiration time (seconds) * * {Number} maxSize: maximum number of cache entries */ protected constructor(cacheId: string, { expirationTime, maxSize }?: CacheOptions); protected abstract load(key: K): Promise; /** * Gets a cached value. * * @param {K} key the cache key * @param {Boolean} force whether to force the cache refresh for that key (default: false) * @return {Promise} the cached value */ get(key: K, force?: boolean): Promise; /** * @override * * Gets a cached value with additional metadata. * * @param {K} key the cache key * @param {Boolean} force whether to force the cache refresh for that key (default: false) * @return {Promise>} the cached value */ getWithMetadata(key: K, force?: boolean): Promise>; set(key: K, value: V): Promise; /** * Checks if a cache entry exists for a given key. * * @param {String} key * @return {Boolean} true if the entry exists in the cache, false otherwise */ exists(key: K): Promise; /** * Deletes a cache entry for a given key. * * @param {String} key */ delete(key: K): Promise; /** * Deletes all entries in the cache; */ reset(): Promise; getCacheId(): string; getCacheDefinition(): CacheDefinition; protected keyToString(key: K): string; protected serialize(value: V): any; protected deserialize(value: any): V; protected addMetadata(metadata: CacheMetadata): void; /** * Gets a value for a key, loading it through the cache loader when the cache holds nothing for that key. * * A cached value of null or undefined counts as nothing cached, and triggers a load. * * @param {K} key the cache key * @param {Boolean} force whether to force the cache refresh for that key * @return {Promise} the value, and whether it came from the cache */ private doGet; private doLoadAndSet; private switchToLRUMode; private switchToRedisMode; } export interface CacheOptions { expirationTime?: number; maxSize?: number; } export interface Metadata { value: V; cached: boolean; time: number; } export interface CacheDefinition { id: string; options: { expirationTime: string; maxSize: number; }; metadata: CacheMetadata; } export interface CacheMetadata { type?: string; class?: string; }