From 8a50a29014fb7a3b22ab4202a2241e1cb2f3281d 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 | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/runtime/caches/redis.ts b/runtime/caches/redis.ts index 6be2576c..5031f7f1 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, @@ -119,15 +120,7 @@ export const caches: CacheStorage = { const cacheKey = await generateKey(request); serialize(response) - .then((data) => { - const expirationTimestamp = Date.parse( - response.headers.get("expires") ?? "", - ); - - const ttl = expirationTimestamp - Date.now(); - - return redis?.set(cacheKey, data, { PX: ttl }); - }) + .then((data) => redis?.set(cacheKey, data, { EX: TTL })) .catch(() => {}); }, });