UNPKG

1.47 kBTypeScriptView Raw
1/**
2 * @template K, V
3 */
4export class Cache<K, V> {
5 /**
6 * @param {number} timeout
7 */
8 constructor(timeout: number);
9 timeout: number;
10 /**
11 * @type list.List<Entry<K, V>>
12 */
13 _q: list.List<Entry<K, V>>;
14 /**
15 * @type {Map<K, Entry<K, V>>}
16 */
17 _map: Map<K, Entry<K, V>>;
18}
19export function removeStale<K, V>(cache: Cache<K, V>): number;
20export function set<K, V>(cache: Cache<K, V>, key: K, value: V): void;
21export function get<K, V>(cache: Cache<K, V>, key: K): V | undefined;
22export function refreshTimeout<K, V>(cache: Cache<K, V>, key: K): void;
23export function getAsync<K, V>(cache: Cache<K, V>, key: K): V | Promise<V> | undefined;
24export function remove<K, V>(cache: Cache<K, V>, key: K): V | undefined;
25export function setIfUndefined<K, V>(cache: Cache<K, V>, key: K, init: () => Promise<V>, removeNull?: boolean): V | Promise<V>;
26export function create(timeout: number): Cache<any, any>;
27import * as list from "./list.js";
28/**
29 * @template K, V
30 *
31 * @implements {list.ListNode}
32 */
33declare class Entry<K, V> implements list.ListNode {
34 /**
35 * @param {K} key
36 * @param {V | Promise<V>} val
37 */
38 constructor(key: K, val: V | Promise<V>);
39 /**
40 * @type {this | null}
41 */
42 prev: Entry<K, V> | null;
43 /**
44 * @type {this | null}
45 */
46 next: Entry<K, V> | null;
47 created: number;
48 val: V | Promise<V>;
49 key: K;
50}
51export {};
52//# sourceMappingURL=cache.d.ts.map
\No newline at end of file