UNPKG

1.6 kBTypeScriptView Raw
1/**
2 * Cache Interface
3 */
4export interface ICache {
5 /** Put item into cache */
6 setItem(key: string, value: any, options?: CacheItemOptions): void;
7 /** Get item from cache */
8 getItem(key: string, options?: CacheItemOptions): any;
9 /** Remove item from cache */
10 removeItem(key: string): void;
11 /** Remove all items from cache */
12 clear(): void;
13 /** Get all keys form cache */
14 getAllKeys(): string[] | Promise<string[]>;
15 /** Get current size of the cache */
16 getCacheCurSize(): number | Promise<number>;
17 /** create a new instance with customized config */
18 createInstance(config: CacheConfig): ICache;
19 /** change current configuration */
20 configure(config: CacheConfig): CacheConfig;
21}
22/**
23 * Cache instance options
24 */
25export interface CacheConfig {
26 /** Prepend to key to avoid conflicts */
27 keyPrefix?: string;
28 /** Cache capacity, in bytes */
29 capacityInBytes?: number;
30 /** Max size of one item */
31 itemMaxSize?: number;
32 /** Time to live, in milliseconds */
33 defaultTTL?: number;
34 /** Warn when over threshold percentage of capacity, maximum 1 */
35 warningThreshold?: number;
36 /** default priority number put on cached items */
37 defaultPriority?: number;
38 storage?: Storage;
39 Cache?: Cache;
40}
41export interface CacheItem {
42 key: string;
43 data: any;
44 timestamp: number;
45 visitedTime: number;
46 priority: number;
47 expires: number;
48 type: string;
49 byteSize: number;
50}
51export interface CacheItemOptions {
52 priority?: number;
53 expires?: number;
54 callback?: Function;
55}