({ cacheKey, cacheType })
| 457 | } |
| 458 | |
| 459 | async getCacheEntry({ cacheKey, cacheType }) { |
| 460 | try { |
| 461 | const rawValue = await this.store.get(cacheKey); |
| 462 | if (!rawValue) { |
| 463 | this.debugLog("cache_miss", { cacheType, cacheKey }); |
| 464 | return null; |
| 465 | } |
| 466 | |
| 467 | const parsedValue = typeof rawValue === "string" ? JSON.parse(rawValue) : rawValue; |
| 468 | const now = Date.now(); |
| 469 | const isFresh = parsedValue.freshUntil > now; |
| 470 | const isStale = !isFresh && parsedValue.staleUntil > now; |
| 471 | |
| 472 | if (!isFresh && !isStale) { |
| 473 | await this.store.del(cacheKey); |
| 474 | this.debugLog("cache_expired", { cacheType, cacheKey }); |
| 475 | return null; |
| 476 | } |
| 477 | |
| 478 | this.debugLog("cache_hit", { |
| 479 | cacheType, |
| 480 | cacheKey, |
| 481 | stale: isStale, |
| 482 | fresh: isFresh, |
| 483 | }); |
| 484 | return { |
| 485 | key: cacheKey, |
| 486 | cacheType, |
| 487 | payload: parsedValue.payload, |
| 488 | stale: isStale, |
| 489 | fresh: isFresh, |
| 490 | createdAt: parsedValue.createdAt, |
| 491 | freshUntil: parsedValue.freshUntil, |
| 492 | staleUntil: parsedValue.staleUntil, |
| 493 | }; |
| 494 | } catch (error) { |
| 495 | this.debugLog("cache_read_error", { |
| 496 | cacheType, |
| 497 | cacheKey, |
| 498 | error: error.message, |
| 499 | }); |
| 500 | return null; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | async setCacheEntry({ cacheKey, payload, ttlMs, staleTtlMs, registryKey }) { |
| 505 | const createdAt = Date.now(); |
no test coverage detected