ddnet
Version:
A typescript npm package for interacting with data from ddnet.org
78 lines (77 loc) • 1.64 kB
TypeScript
/**
* A simple cache manager.
*
* @typeParam T The type of the cached objects.
*/
export declare class CacheManager<T> {
/**
* Data store.
*/
private store;
/**
* "Time-To-Live" - How much time (in milliseconds) before a cached object becomes stale, and thus removed automatically.
*
* Changing this value does not affect old objects.
*
* @default 7200000 // 2 hours
*/
private ttl;
/**
* Default TTL.
*/
private static defaultTTL;
/**
* Construct a new {@link CacheManager} instance.
*/
constructor(
/**
* The namespace to use for this cache.
*/
namespace: string,
/**
* The TTL (Time-To-Live) for objects in cache.
*
* @default 7200000 // 2 hours
*/
ttl?: number);
/**
* Sets a key to a value in the cache.
*/
set(
/**
* The key to set.
*/
key: string,
/**
* The value to set.
*/
value: T): Promise<void>;
/**
* Gets the value of the given key from the cache.
*/
get(
/**
* The key to get.
*/
key: string): Promise<T | undefined>;
/**
* Checks if the cache has a value for the given key.
*/
has(
/**
* The key to check.
*/
key: string): Promise<boolean>;
/**
* Sets the {@link CacheManager.ttl}.
*/
setTTL(
/**
* If provided, sets the {@link CacheManager.ttl} to this value, otherwise uses the default value.
*/
ttlMS?: number): void;
/**
* Clears the {@link CacheManager.store}.
*/
clearCache(): Promise<void>;
}