@launchdarkly/js-server-sdk-common
Version:
LaunchDarkly Server SDK for JavaScript - common code
53 lines • 1.53 kB
TypeScript
/**
* Options for the TTL cache.
*/
export interface TtlCacheOptions {
/**
* The TTL for all items in seconds.
*/
ttl: number;
/**
* Time, in seconds, to check for expired items and purge them from the cache.
*/
checkInterval: number;
}
/**
* A basic TTL cache with configurable TTL and check interval.
*/
export default class TtlCache {
private readonly _options;
private _storage;
private _checkIntervalHandle;
constructor(_options: TtlCacheOptions);
/**
* Get a value from the cache.
* @param key The key to get a value for.
* @returns The value for the key, or undefined if the key was not added, or
* if the value has expired.
*/
get(key: string): any;
/**
* Set an item in the cache. It will expire after the TTL specified
* in the cache configuration.
* @param key The key for the value.
* @param value The value to set.
*/
set(key: string, value: any): void;
/**
* Delete the item with the specific key. If the item does not exist,
* then there will be no change to the cache.
* @param key The key of the value to delete.
*/
delete(key: string): void;
/**
* Clear the items that are in the cache.
*/
clear(): void;
/**
* Indicate that you are no longer going to use the cache. The cache will be
* cleared and it will stop checking for stale items.
*/
close(): void;
private _purgeStale;
}
//# sourceMappingURL=TtlCache.d.ts.map