mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-01-30 16:43:37 +00:00
Fixed Cache Handler
This commit is contained in:
parent
e9b6d28591
commit
e55fe00bad
1 changed files with 7 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue