Skip to content

Commit

Permalink
feat: define a default TTL specifically for redis cache
Browse files Browse the repository at this point in the history
  • Loading branch information
azisaka committed Nov 19, 2024
1 parent 15e0d76 commit 8a50a29
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") || "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 8a50a29

Please sign in to comment.