UNPKG

tsbase

Version:

Base class libraries for TypeScript

24 lines (23 loc) 1.1 kB
import { IGenericStorage } from '../../Persistence/GenericStorage/IGenericStorage'; import { JsonSerializer } from '../../Utility/Serialization/JsonSerializer'; import { ICache } from './ICache'; import { Result } from '../../Patterns/Result/Result'; export declare class Cache<T> implements ICache<T> { private storage; private cacheLife; private serializer; /** * @param storage the storage interface used to support caching * @param cacheLife EITHER 1.) the amount of milliseconds after the cache is created till it is invalidated | * leaving the default value (0) will result prevent any auto clearing of cache entries * OR 2.) a function defining when the cache is no longer valid; a "false" return will invalidate the cache * @param serializer */ constructor(storage: IGenericStorage, cacheLife?: number | ((entry: T) => boolean), serializer?: JsonSerializer); Add(key: string, value: T): Result<null>; Get(key: string, type?: { new (): T; }): T | null; Delete(key: string): Result<null>; private cacheIsValid; }