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 f1d1af4
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 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 @@ -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 });
})
Expand Down

0 comments on commit f1d1af4

Please sign in to comment.