UNPKG

2.23 kBTypeScriptView Raw
1export interface LiteralObject {
2 [key: string]: any;
3}
4/**
5 * Interface defining a cache store. Implement this interface to create a custom
6 * cache store.
7 *
8 * @publicApi
9 */
10export interface CacheStore {
11 /**
12 * Create a key/value pair in the cache.
13 *
14 * @param key cache key
15 * @param value cache value
16 */
17 set<T>(key: string, value: T, options?: CacheStoreSetOptions<T> | number): Promise<void> | void;
18 /**
19 * Retrieve a key/value pair from the cache.
20 *
21 * @param key cache key
22 */
23 get<T>(key: string): Promise<T | undefined> | T | undefined;
24 /**
25 * Destroy a key/value pair from the cache.
26 *
27 * @param key cache key
28 */
29 del?(key: string): void | Promise<void>;
30}
31export interface CacheStoreSetOptions<T> {
32 /**
33 * Time to live - amount of time in seconds that a response is cached before it
34 * is deleted. Defaults based on your cache manager settings.
35 */
36 ttl?: ((value: T) => number) | number;
37}
38/**
39 * Interface defining a factory to create a cache store.
40 *
41 * @publicApi
42 */
43export interface CacheStoreFactory {
44 /**
45 * Return a configured cache store.
46 *
47 * @param args Cache manager options received from `CacheModule.register()`
48 * or `CacheModule.registerAsync()`
49 */
50 create(args: LiteralObject): CacheStore;
51}
52/**
53 * Interface defining Cache Manager configuration options.
54 *
55 * @publicApi
56 */
57export interface CacheManagerOptions {
58 /**
59 * Cache storage manager. Default is `'memory'` (in-memory store). See
60 * [Different stores](https://docs.nestjs.com/techniques/caching#different-stores)
61 * for more info.
62 */
63 store?: string | CacheStoreFactory | CacheStore;
64 /**
65 * Time to live - amount of time that a response is cached before it
66 * is deleted. Subsequent request will call through the route handler and refresh
67 * the cache. Defaults to 5 seconds. In `cache-manager@^4` this value is in seconds.
68 * In `cache-manager@^5` this value is in milliseconds.
69 */
70 ttl?: number;
71 /**
72 * Maximum number of responses to store in the cache. Defaults to 100.
73 */
74 max?: number;
75 isCacheableValue?: (value: any) => boolean;
76}
77
\No newline at end of file