Skip to content

Commit

Permalink
cacheable - fix: when found on secondary use expires to set primary (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray authored Jan 7, 2025
1 parent 7933056 commit e2e0352
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/cacheable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit e2e0352

Please sign in to comment.