From e55fe00bad6f06554cdd13df7d3402f9a8f20452 Mon Sep 17 00:00:00 2001 From: Ahmad <103906421+ahmadk953@users.noreply.github.com> Date: Sun, 26 Jan 2025 15:44:15 -0500 Subject: [PATCH] Fixed Cache Handler --- cache-handler.mjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cache-handler.mjs b/cache-handler.mjs index a6debc3..76b1b07 100644 --- a/cache-handler.mjs +++ b/cache-handler.mjs @@ -1,4 +1,4 @@ -import redis from './lib/redis' +import redis from './lib/redis.ts'; export default class CacheHandler { constructor(options) { @@ -20,7 +20,7 @@ export default class CacheHandler { const cacheData = { value: data, lastModified: Date.now(), - tags: ctx.tags, + tags: ctx.tags || [], }; await redis.set(key, JSON.stringify(cacheData)); } catch (error) { @@ -34,9 +34,12 @@ export default class CacheHandler { const keys = await redis.keys('*'); for (const key of keys) { const value = await redis.get(key); - if (value) { + if (value && tags.length > 0) { const parsed = JSON.parse(value); - if (parsed.tags.some((tag) => tags.includes(tag))) { + if ( + Array.isArray(parsed.tags) && + parsed.tags.some((tag) => tags.includes(tag)) + ) { await redis.del(key); } }