@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
75 lines • 3.02 kB
TypeScript
import { type PickPartial } from "../internal/misc";
import type { Loggers } from "./Loggers";
export interface LocalCacheOptions {
/** Directory to store the cache in (auto-created). */
dir: string;
/** Loggers for e.g. swallowed errors. */
loggers: Pick<Loggers, "swallowedErrorLogger">;
/** Max time (approximately) for an unread key to exist. */
expirationMs?: number;
/** Extension of cache files (without dot). */
ext?: string;
/** Jitter for cleanup runs. */
cleanupJitter?: number;
/** How much time to wait till the very 1st cleanup run. The idea is that Node
* process may be short-lived, so the next cleanup run configured via
* cleanupRoundsPerExpiration may never happen, and we also need to cleanup in
* the very beginning of the object lifetime. */
cleanupFirstRunDelayMs?: number;
/** How many times per expirationMs interval should we run the cleanup. */
cleanupRoundsPerExpiration?: number;
/** How often to update mtime on read operations. E.g. if this value is 10,
* then mtime will be updated not more than ~10 times within the expiration
* period (optimizing filesystem writes). */
mtimeUpdatesOnReadPerExpiration?: number;
}
/**
* A simple key-value cache stored on the local machine.
*
* - The expectation is that there will be not too many keys stored, since the
* background cleanup process running time to time is O(numKeysStored).
* - Guarantees corruption-free writes to the keys from multiple processes
* running concurrently.
* - The values which are not requested longer than approximately `expirationMs`
* are auto-removed.
* - Each key is stored in an individual file under `dir`. Some temporary files
* may also appear in that directory, but eventually, they will be cleaned up,
* even if they get stuck for some time.
*/
export declare class LocalCache<TValue extends {} = never> {
/** Default values for the constructor options. */
static readonly DEFAULT_OPTIONS: Required<PickPartial<LocalCacheOptions>>;
private cleanupTimeout?;
/** LocalCache configuration options. */
readonly options: Required<LocalCacheOptions>;
/**
* Initializes the instance.
*/
constructor(options: LocalCacheOptions);
/**
* Ends the instance lifecycle (e.g. garbage recheck interval).
*/
end(): void;
/**
* Returns the value for the given key, or null if the key does not exist.
*/
get(key: string): Promise<TValue | null>;
/**
* Sets the value for the given key.
*/
set(key: string, value: TValue): Promise<void>;
/**
* Deletes the values for keys which were not accessed for a long time.
*/
private cleanup;
/**
* Runs then the instance creates (with initial small jitter) and also
* periodically.
*/
private onCleanupTimer;
/**
* Builds the full path to a file for a given key.
*/
private buildPath;
}
//# sourceMappingURL=LocalCache.d.ts.map