UNPKG

adonis5-cache

Version:
48 lines (47 loc) 2.26 kB
import { CacheConfig, CacheContextContract, CacheManagerContract, CacheStorageContract, AsyncFunction, ConstructorParams } from '@ioc:Adonis/Addons/Adonis5-Cache'; import CacheEventEmitter from './CacheEventEmitter'; import TaggableCacheManager from './TaggableCacheManager'; export declare type CacheStorageCollection = { [key: string]: CacheStorageContract; }; export declare type CacheContextCollection = { [key: string]: CacheContextContract; }; export default class CacheManager implements CacheManagerContract { static readonly DEFAULT_RECORD_TTL = 6000; protected cacheStorages: CacheStorageCollection; protected cacheContexts: CacheContextCollection; protected cacheConfig: CacheConfig; protected currentCacheStorageName: string; protected currentCacheContextName: string; protected tempContextName: string | null; protected tempStorageName: string | null; protected eventEmitter: CacheEventEmitter; protected cacheTags: string[]; constructor({ config, eventEmitter }: ConstructorParams); get recordTTL(): number; get recordKeyPrefix(): string; get context(): CacheContextContract; get storage(): CacheStorageContract; registerStorage(storageName: string, storage: CacheStorageContract): CacheManagerContract; registerContext(contextName: string, context: CacheContextContract): CacheManagerContract; viaContext(contextName: string): CacheManagerContract; viaStorage(storageName: string): CacheManagerContract; tags(...tags: string[]): TaggableCacheManager; enableStorage(storageName: string): CacheManagerContract; enableContext(contextName: string): CacheManagerContract; get<T = any>(key: string, fallback?: T | AsyncFunction<T>, ttl?: number): Promise<T | null>; getMany<T = any>(keys: string[]): Promise<(T | null)[]>; put<T = any>(key: string, value: T, ttl?: number): Promise<void>; putMany<T = any>(cacheDictionary: { [p: string]: T; }, ttl?: number): Promise<void>; flush(): Promise<void>; forget(key: string): Promise<boolean>; private buildRecordKey; private restoreState; private emitEventsOnReadOperations; private initCacheContexts; private resolveFallback; private resolveCacheTTL; }