diff --git a/utils/getOrSetCache.js b/utils/getOrSetCache.js index 35cccc8..7ec01fa 100644 --- a/utils/getOrSetCache.js +++ b/utils/getOrSetCache.js @@ -4,7 +4,10 @@ const ttl = process.env.REDIS_TTL || 3600; const getOrSetCache = async (key, callback, ...callbackArgs) => { const data = await redis.get(key); - if (data) return JSON.parse(data); + if (data) { + await redis.expire(key, ttl); + return JSON.parse(data); + } const dataToCache = await callback(...callbackArgs); await redis.set(key, JSON.stringify(dataToCache), 'EX', ttl); diff --git a/utils/redis.js b/utils/redis.js index e49c1f3..6ff55a6 100644 --- a/utils/redis.js +++ b/utils/redis.js @@ -6,6 +6,7 @@ const redisUrl = process.env.REDIS_URL; const stub = { get: async key => {}, set: async (key, value, secondsToken, seconds) => {}, + expire: async (key, seconds) => {}, }; const redis = redisUrl ? new Redis(redisUrl) : stub;