/** @packageDocumentation * @module Core */ /** * Configuration properties for [[TemporaryStorage]]. * @internal */ export interface TemporaryStorageProps { /** A method that's called for every value before it's removed from storage */ cleanupHandler?: (id: string, value: T, reason: "timeout" | "dispose" | "request" | "eviction") => void; onDisposedSingle?: (id: string) => void; onDisposedAll?: () => void; /** * An interval at which the storage attempts to clean up its values. * When `0` or `undefined` is specified, values are not cleaned up * automatically and cleanup has to be initiated manually by calling * [[TemporaryStorage.disposeOutdatedValues]]. */ cleanupInterval?: number; /** * Shortest period of time which the value should be kept in storage * unused before it's cleaned up. * * `undefined` means the values may be kept unused in the storage indefinitely. * `0` means the values are removed from the storage on every cleanup (either manual * call to [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled * by [[cleanupInterval]])). */ unusedValueLifetime?: number; /** * The maximum period of time which the value should be kept in storage * before it's cleaned up. The time is measured from the moment the value is added * to the storage. * * `undefined` means the values may be kept indefinitely. `0` means they're removed * up on every cleanup (either manual call to [[TemporaryStorage.disposeOutdatedValues]] * or scheduled (controlled by [[cleanupInterval]])). */ maxValueLifetime?: number; /** * The maximum number of values the storage is allowed to hold at once. When adding * a value would exceed this limit, the least-recently-used value is evicted first. * * `undefined` (or any value less than `1`) means the number of values is not capped. */ maxValues?: number; } /** Value with know last used time */ interface TemporaryValue { created: Date; lastUsed: Date; value: T; } /** * Storage for values that get removed from it after being unused (not-requested * for a specified amount of time). * * @internal */ export declare class TemporaryStorage implements Disposable { private _timer?; protected _values: Map>; readonly props: TemporaryStorageProps; /** * Constructor. Creates the storage using supplied params. */ constructor(props: TemporaryStorageProps); /** * Destructor. Must be called to clean up the stored values * and other resources */ [Symbol.dispose](): void; /** * Cleans up values that are currently outdated (based * on their max and unused value lifetimes specified through [[Props]]). */ disposeOutdatedValues: () => void; private deleteExistingEntry; /** * Evicts least-recently-used values until there's room to add one more value * without exceeding the configured [[TemporaryStorageProps.maxValues]] limit. */ private evictForNewValue; /** * Get a value from the storage. * * **Note:** requesting a value with this method updates it's last used time. */ getValue(id: string): T | undefined; notifyValueUsed(id: string): void; /** * Adds a value into the storage. * @throws An error when trying to add a value with ID that's already stored in the storage. */ addValue(id: string, value: T): void; /** Deletes a value with given id. */ deleteValue(id: string): void; /** * Get all values currently in this storage. * * **Note:** requesting values with this method **doesn't** * update their last used times. */ get values(): T[]; } /** * Configuration properties for [[FactoryBasedTemporaryStorage]]. * @internal */ export interface FactoryBasedTemporaryStorageProps extends TemporaryStorageProps { /** A factory method that creates a stored value given it's identifier */ factory: (id: string, onValueUsed: () => void) => T; } /** * Storage for values that get removed from it after being unused (not-requested * for a specified amount of time). * * @internal */ export declare class FactoryBasedTemporaryStorage extends TemporaryStorage { readonly props: FactoryBasedTemporaryStorageProps; /** * Constructor. Creates the storage using supplied params. */ constructor(props: FactoryBasedTemporaryStorageProps); /** * Get a value from the storage. If the value with the specified id * doesn't exist, it gets created. * * **Note:** requesting a value with this method updates it's last used time. */ getValue(id: string): T; } export {}; //# sourceMappingURL=TemporaryStorage.d.ts.map