1
1
import { DynamicModule , Module } from '@nestjs/common' ;
2
- import type { Cache as CoreCache } from 'cache-manager'
2
+ import { Events } from 'cache-manager' ;
3
3
import { CACHE_MANAGER } from './cache.constants' ;
4
4
import { ConfigurableModuleClass } from './cache.module-definition' ;
5
5
import { createCacheManager } from './cache.providers' ;
6
6
import {
7
7
CacheModuleAsyncOptions ,
8
8
CacheModuleOptions ,
9
9
} from './interfaces/cache-module.interface' ;
10
+ import EventEmitter from 'node:events' ;
10
11
11
12
/**
12
13
* This is just the same as the `Cache` interface from `cache-manager` but you can
@@ -15,7 +16,41 @@ import {
15
16
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
16
17
export abstract class Cache { }
17
18
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
18
- export interface Cache extends CoreCache { }
19
+ export interface Cache {
20
+ get : < T > ( key : string ) => Promise < T | null > ;
21
+ mget : < T > ( keys : string [ ] ) => Promise < ( Awaited < T > | null ) [ ] > ;
22
+ set : < T > ( key : string , value : T , ttl ?: number ) => Promise < T > ;
23
+ mset : < T > (
24
+ list : Array < {
25
+ key : string ;
26
+ value : T ;
27
+ ttl ?: number ;
28
+ } > ,
29
+ ) => Promise <
30
+ {
31
+ key : string ;
32
+ value : T ;
33
+ ttl ?: number ;
34
+ } [ ]
35
+ > ;
36
+ del : ( key : string ) => Promise < boolean > ;
37
+ mdel : ( keys : string [ ] ) => Promise < boolean > ;
38
+ clear : ( ) => Promise < boolean > ;
39
+ wrap : < T > (
40
+ key : string ,
41
+ fnc : ( ) => T | Promise < T > ,
42
+ ttl ?: number | ( ( value : T ) => number ) ,
43
+ refreshThreshold ?: number ,
44
+ ) => Promise < T > ;
45
+ on : < E extends keyof Events > (
46
+ event : E ,
47
+ listener : Events [ E ] ,
48
+ ) => EventEmitter < [ never ] > ;
49
+ off : < E extends keyof Events > (
50
+ event : E ,
51
+ listener : Events [ E ] ,
52
+ ) => EventEmitter < [ never ] > ;
53
+ }
19
54
20
55
/**
21
56
* Module that provides Nest cache-manager.
@@ -30,7 +65,7 @@ export interface Cache extends CoreCache {}
30
65
{
31
66
provide : Cache ,
32
67
useExisting : CACHE_MANAGER ,
33
- }
68
+ } ,
34
69
] ,
35
70
exports : [ CACHE_MANAGER , Cache ] ,
36
71
} )
0 commit comments