mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-01-31 00:53: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 {
|
export default class CacheHandler {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -20,7 +20,7 @@ export default class CacheHandler {
|
||||||
const cacheData = {
|
const cacheData = {
|
||||||
value: data,
|
value: data,
|
||||||
lastModified: Date.now(),
|
lastModified: Date.now(),
|
||||||
tags: ctx.tags,
|
tags: ctx.tags || [],
|
||||||
};
|
};
|
||||||
await redis.set(key, JSON.stringify(cacheData));
|
await redis.set(key, JSON.stringify(cacheData));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -34,9 +34,12 @@ export default class CacheHandler {
|
||||||
const keys = await redis.keys('*');
|
const keys = await redis.keys('*');
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const value = await redis.get(key);
|
const value = await redis.get(key);
|
||||||
if (value) {
|
if (value && tags.length > 0) {
|
||||||
const parsed = JSON.parse(value);
|
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);
|
await redis.del(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue