@linkedmink/multilevel-aging-cache
Version:
Package provides an interface to cache and persist data to Redis, MongoDB, memory
85 lines • 4.09 kB
TypeScript
import { IStorageProvider } from './IStorageProvider';
import { AgedCompareFunc, IAgedValue } from '../queue/IAgedQueue';
import { IDisposable } from '../shared/IDisposable';
import { IStorageHierarchy, StorageHierarchyUpdatePolicy, IStorageHierarchyWrite } from './IStorageHierarchy';
/**
* The default storage hierarchy implementation relying on IStorageProvider for actual data access
*/
export declare class StorageHierarchy<TKey, TValue> implements IStorageHierarchy<TKey, TValue>, IDisposable {
private readonly levels;
private readonly updatePolicy;
private readonly ageCompareFunc;
readonly totalLevels: number;
readonly isPersistable: boolean;
private readonly logger;
private readonly storageChangedHandlers;
private readonly pendingUpdates;
private readonly topLevel;
private readonly publishLevel?;
/**
* @param levels The levels in the hierarchy with index 0 being the lowest level (first to read)
* @param updatePolicy How updates from subscribed higher level storage providers should be handled
*/
constructor(levels: IStorageProvider<TKey, TValue>[], updatePolicy?: StorageHierarchyUpdatePolicy, ageCompareFunc?: AgedCompareFunc);
/**
* Clean up the object when it's no longer used. After a dispose(), an object
* is no longer guaranteed to be usable.
*/
dispose(): Promise<void>;
/**
* @param key The key to retrieve
* @param level The level at which to retrieve the key
* @param isAscending To go up the hierarchy (true) or down (false) from level
* @returns The value if it's in the hierarchy from the level going up/down or null
*/
getAtLevel(key: TKey, level?: number, isAscending?: boolean): Promise<IAgedValue<TValue> | null>;
/**
* @param key The key to set
* @param value The value to set
* @param level The level at which to set the key
* @param isAscending To go up the hierarchy (true) or down (false) from level
* @returns If the write succeeded to all levels going up/down or the error condition
*/
setAtLevel(key: TKey, value: IAgedValue<TValue>, level?: number, isAscending?: boolean): Promise<IStorageHierarchyWrite<TValue>>;
/**
* @param key The key to delete
* @param level The level at which to delete the key
* @param isAscending To go up the hierarchy (true) or down (false) from level
* @returns If the write succeeded to all levels going up/down or the error condition
*/
deleteAtLevel(key: TKey, level?: number, isAscending?: boolean, writtenValue?: IAgedValue<TValue>): Promise<IStorageHierarchyWrite<TValue>>;
/**
* @param level The level at which to search
* @return The number of keys at the specified level
*/
getSizeAtLevel(level: number): Promise<number>;
/**
* @returns The keys a the top level (should be all keys across the entire hierarchy)
*/
getKeysAtTopLevel(): Promise<TKey[]>;
/**
* @param key The key to retrieve
* @returns The value at the top level only or null
*/
getValueAtTopLevel(key: TKey): Promise<IAgedValue<TValue> | null>;
/**
* @param key The key to retrieve
* @returns The value at the bottom level only or null
*/
getValueAtBottomLevel(key: TKey): Promise<IAgedValue<TValue> | null>;
/**
* Set only the levels below the top level (for refresing from the top level for instance)
* @param key The key to set
* @param value The value to set
* @returns If the write succeeded to all levels going up/down or the error condition
*/
setBelowTopLevel(key: TKey, value: IAgedValue<TValue>): Promise<IStorageHierarchyWrite<TValue>>;
private subscribeAtLevel;
private getCurrentLevelOrNull;
private getUpdateHandlerAlways;
private getUpdateHandlerOnlyIfKeyExist;
private getManagedPromiseSubscribe;
private getPartialWriteStatus;
private getFullWriteStatus;
}
//# sourceMappingURL=StorageHierarchy.d.ts.map