From e2e035296810b704b9a6e06a2628bdfa7ed1bfa0 Mon Sep 17 00:00:00 2001 From: Jared Wray Date: Tue, 7 Jan 2025 12:44:56 -0800 Subject: [PATCH] cacheable - fix: when found on secondary use expires to set primary (#972) --- packages/cacheable/src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/cacheable/src/index.ts b/packages/cacheable/src/index.ts index d7cd10c3..7e048187 100644 --- a/packages/cacheable/src/index.ts +++ b/packages/cacheable/src/index.ts @@ -270,9 +270,10 @@ export class Cacheable extends Hookified { await this.hook(CacheableHooks.BEFORE_GET, key); result = await this._primary.get(key) as T; if (!result && this._secondary) { - result = await this._secondary.get(key) as T; - if (result) { - const finalTtl = shorthandToMilliseconds(this._ttl); + const rawResult = await this._secondary.get(key, {raw: true}); + if (rawResult) { + result = rawResult.value as T; + const finalTtl = rawResult.expires ?? shorthandToMilliseconds(this._ttl); await this._primary.set(key, result, finalTtl); } }