From 4cbe6a204bf4e1ea821767780bf6ad8ae7542eb0 Mon Sep 17 00:00:00 2001 From: Vedant K Date: Sat, 16 Sep 2023 12:49:41 +0530 Subject: [PATCH] fix: `this.expiration` should be in ms when added to `Date.now()` --- source/memcached-store.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/memcached-store.ts b/source/memcached-store.ts index 1cda357..bbc2cb9 100644 --- a/source/memcached-store.ts +++ b/source/memcached-store.ts @@ -144,7 +144,7 @@ class MemcachedStore implements Store { totalHits = 1 // When you set it to 1, it returns `true` for some reason. // Also store the expiration time in a separate key. - expiresAt = Date.now() + this.expiration + expiresAt = Date.now() + this.expiration * 1000 // [seconds -> milliseconds] await this.fns.set( this.expiryKey(key), // The name of the key. expiresAt, // The value - the time at which the key expires. @@ -163,7 +163,9 @@ class MemcachedStore implements Store { // Return the total number of hits, as well as the reset timestamp. return { totalHits, - resetTime: expiresAt === undefined ? undefined : new Date(expiresAt), + // If `expiresAt` is undefined, assume the key expired sometime in between + // reading the hits and expiry keys from memcached. + resetTime: expiresAt ? new Date(expiresAt) : new Date(), } }