@@ -5,6 +5,7 @@ import * as Redis from "ioredis";
5
5
6
6
export class LRUWithRedisStorage implements AsynchronousCacheType {
7
7
private myCache : LRU < string , any > ;
8
+ /** maxAge and ttl in seconds! */
8
9
private options : LRU . Options < string , any > ;
9
10
10
11
constructor (
@@ -16,7 +17,10 @@ export class LRUWithRedisStorage implements AsynchronousCacheType {
16
17
maxAge : 86400 ,
17
18
...options
18
19
}
19
- this . myCache = new LRU ( this . options ) ;
20
+ this . myCache = new LRU ( {
21
+ ...this . options ,
22
+ maxAge : ( this . options . maxAge || 86400 ) * 1000 // in ms
23
+ } ) ;
20
24
}
21
25
22
26
public async getItem < T > ( key : string ) : Promise < T | undefined > {
@@ -42,6 +46,7 @@ export class LRUWithRedisStorage implements AsynchronousCacheType {
42
46
return localCache ?? undefined ;
43
47
}
44
48
49
+ /** ttl in seconds! */
45
50
public async setItem ( key : string , content : any , options ?: { ttl ?: number } ) : Promise < void > {
46
51
this . myCache . set ( key , content ) ;
47
52
if ( this . options ?. maxAge ) {
@@ -53,6 +58,9 @@ export class LRUWithRedisStorage implements AsynchronousCacheType {
53
58
54
59
public async clear ( ) : Promise < void > {
55
60
// flush not supported, recreate local lru cache instance
56
- this . myCache = new LRU ( this . options ) ;
61
+ this . myCache = new LRU ( {
62
+ ...this . options ,
63
+ maxAge : ( this . options . maxAge || 86400 ) * 1000 // in ms
64
+ } ) ;
57
65
}
58
66
}
0 commit comments