Skip to content

Commit

Permalink
Merge pull request #869 from azisaka/feat/redis-cache-default-ttl
Browse files Browse the repository at this point in the history
feat: define a default TTL specifically for redis cache
  • Loading branch information
vitortrindader authored Nov 19, 2024
2 parents 15e0d76 + a54665c commit ebe6471
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions runtime/caches/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

const CONNECTION_TIMEOUT = 500;
const RECONNECTION_TIMEOUT = 5000;
const TTL = parseInt(Deno.env.get("LOADER_CACHE_REDIS_TTL_SECONDS") || "3600");

type RedisConnection = RedisClientType<
RedisModules,
Expand Down Expand Up @@ -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(() => {});
},
});
Expand Down

0 comments on commit ebe6471

Please sign in to comment.