@@ -467,52 +467,20 @@ describe.sequential('cache-with-ttl', () => {
467467 await refreshCache . clear ( )
468468 } )
469469
470- it ( 'should treat far-future expiresAt as expired (clock skew protection)' , async ( ) => {
471- // This tests the fix in cache-with-ttl.ts:190-203
472- // The isExpired() function checks if expiresAt > now + ttl * 2
473- // to detect clock skew or corruption
474-
475- const clockSkewCache = createTtlCache ( {
476- ttl : 1000 , // 1 second TTL
477- prefix : 'clock-skew-test' ,
478- memoize : true , // Use memoization to test the isExpired logic directly
479- } )
480-
481- // Set a value - this will create an entry with normal expiration
482- await clockSkewCache . set ( 'key' , 'value' )
483-
484- // Verify value is cached
485- expect ( await clockSkewCache . get < string > ( 'key' ) ) . toBe ( 'value' )
486-
487- // The internal isExpired function will reject entries where:
488- // expiresAt > Date.now() + ttl * 2
489- // This protects against clock skew where the system clock jumps forward
490-
491- // Note: We can't easily test the actual clock skew scenario without
492- // manipulating cacache internals, but the fix is in place and handles:
493- // - Entries with far-future expiresAt (>2x TTL) are treated as expired
494- // - Normal future expiresAt values (within TTL) work correctly
495-
496- await clockSkewCache . clear ( )
497- } )
498-
499- it ( 'should handle slightly future expiresAt within reasonable bounds' , async ( ) => {
500- const normalCache = createTtlCache ( {
501- ttl : 5000 , // 5 second TTL
502- prefix : 'normal-future-cache' ,
470+ it ( 'should expire entries and return undefined after TTL (memoized)' , async ( ) => {
471+ const shortCache = createTtlCache ( {
472+ ttl : 200 ,
473+ prefix : 'short-memo-cache' ,
474+ memoize : true ,
503475 } )
504476
505- // Set a value - expiresAt will be Date.now() + 5000
506- await normalCache . set ( 'key' , 'value' )
507-
508- // Value should be retrievable immediately (expiresAt is in future as expected)
509- const result = await normalCache . get < string > ( 'key' )
510- expect ( result ) . toBe ( 'value' )
477+ await shortCache . set ( 'key' , 'value' )
478+ expect ( await shortCache . get < string > ( 'key' ) ) . toBe ( 'value' )
511479
512- // Only far-future values (>2x TTL) should be treated as expired
513- // This tests that normal future expiresAt values work correctly
480+ await new Promise ( resolve => setTimeout ( resolve , 300 ) )
481+ expect ( await shortCache . get < string > ( 'key' ) ) . toBeUndefined ( )
514482
515- await normalCache . clear ( )
483+ await shortCache . clear ( )
516484 } )
517485 } )
518486
0 commit comments