From f1d1af4a750add3534192e7d823c56ac10d77a0c Mon Sep 17 00:00:00 2001 From: Bruno Azisaka Date: Tue, 19 Nov 2024 17:57:58 -0300 Subject: [PATCH] feat: define a default TTL specifically for redis cache --- runtime/caches/redis.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/runtime/caches/redis.ts b/runtime/caches/redis.ts index 6be2576c..36b75a52 100644 --- a/runtime/caches/redis.ts +++ b/runtime/caches/redis.ts @@ -15,6 +15,7 @@ import { const CONNECTION_TIMEOUT = 500; const RECONNECTION_TIMEOUT = 5000; +const TTL = parseInt(Deno.env.get("LOADER_CACHE_REDIS_TTL") || "3600"); type RedisConnection = RedisClientType< RedisModules, @@ -120,11 +121,8 @@ export const caches: CacheStorage = { serialize(response) .then((data) => { - const expirationTimestamp = Date.parse( - response.headers.get("expires") ?? "", - ); - - const ttl = expirationTimestamp - Date.now(); + const now = Date.now(); + const ttl = now + TTL * 1000; return redis?.set(cacheKey, data, { PX: ttl }); })