File tree 2 files changed +10
-3
lines changed
2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export function memoryStore(args?: MemoryConfig): MemoryStore {
36
36
const lruOpts = {
37
37
...args ,
38
38
max : args ?. max || 500 ,
39
- ttl : args ?. ttl ? args . ttl : 0 ,
39
+ ttl : args ?. ttl !== undefined ? args . ttl : 0 ,
40
40
} ;
41
41
42
42
const lruCache = new LRUCache < string , unknown > ( lruOpts ) ;
@@ -49,7 +49,7 @@ export function memoryStore(args?: MemoryConfig): MemoryStore {
49
49
keys : async ( ) => [ ...lruCache . keys ( ) ] ,
50
50
mget : async ( ...args ) => args . map ( ( x ) => lruCache . get ( x ) ) ,
51
51
async mset ( args , ttl ?) {
52
- const opt = { ttl : ttl ? ttl : lruOpts . ttl } as const ;
52
+ const opt = { ttl : ttl !== undefined ? ttl : lruOpts . ttl } as const ;
53
53
for ( const [ key , value ] of args ) {
54
54
if ( ! isCacheable ( value ) )
55
55
throw new Error ( `no cacheable value ${ JSON . stringify ( value ) } ` ) ;
@@ -69,7 +69,7 @@ export function memoryStore(args?: MemoryConfig): MemoryStore {
69
69
throw new Error ( `no cacheable value ${ JSON . stringify ( value ) } ` ) ;
70
70
if ( shouldCloneBeforeSet ) value = clone ( value ) ;
71
71
72
- const ttl = opt ? opt : lruOpts . ttl ;
72
+ const ttl = opt !== undefined ? opt : lruOpts . ttl ;
73
73
74
74
lruCache . set ( key , value , { ttl } ) ;
75
75
} ,
Original file line number Diff line number Diff line change @@ -24,6 +24,13 @@ describe('memory store', () => {
24
24
await expect ( store . get ( 'foo' ) ) . resolves . toEqual ( 'bar' ) ;
25
25
} ) ;
26
26
27
+ it ( 'when ttl arg is passed 0' , async ( ) => {
28
+ const store = memoryStore ( { ttl : 1 } ) ;
29
+ await store . set ( 'foo' , 'bar' , 0 ) ;
30
+ await sleep ( 20 ) ;
31
+ await expect ( store . get ( 'foo' ) ) . resolves . toEqual ( 'bar' ) ;
32
+ } ) ;
33
+
27
34
it ( 'cache record should be expired' , async ( ) => {
28
35
await store . set ( 'foo' , 'bar' , 1 ) ;
29
36
await sleep ( 20 ) ;
You can’t perform that action at this time.
0 commit comments