Skip to content

Commit f5fc559

Browse files
committed
Simplify tag management.
1 parent b3c5054 commit f5fc559

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

.oxlintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"eslint/no-undefined": "off",
2929
"eslint/no-empty-function": "off",
3030
"eslint/no-continue": "off",
31+
"eslint/max-depth": "off",
3132
"eslint/max-statements": "off",
3233
"eslint/no-implicit-coercion": "off",
3334
"eslint/no-plusplus": "off",

packages/cache/src/providers/memory.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ export class MemoryCacheProvider implements CacheProvider {
2222
if (entryIsExpired(entry)) {
2323
this.entryStore.delete(key)
2424
this.options?.onIntervalExpiration?.(entry)
25-
}
26-
}
2725

28-
for (const [tag, keys] of this.tagStore) {
29-
for (const key of keys) {
30-
if (!this.entryStore.has(key)) {
31-
keys.delete(key)
32-
}
33-
}
26+
if (entry.options.tags) {
27+
for (const tag of entry.options.tags) {
28+
const keys = this.tagStore.get(tag)
3429

35-
if (keys.size === 0) {
36-
this.tagStore.delete(tag)
30+
if (!keys) {
31+
continue
32+
}
33+
34+
keys.delete(key)
35+
36+
if (keys.size === 0) {
37+
this.tagStore.delete(tag)
38+
}
39+
}
40+
}
3741
}
3842
}
3943
}
@@ -66,11 +70,15 @@ export class MemoryCacheProvider implements CacheProvider {
6670
for (const tag of options.tags) {
6771
const keys = this.tagStore.get(tag)
6872

69-
if (keys) {
70-
for (const key of keys) {
71-
this.entryStore.delete(key)
72-
}
73+
if (!keys) {
74+
continue
7375
}
76+
77+
for (const key of keys) {
78+
this.entryStore.delete(key)
79+
}
80+
81+
this.tagStore.delete(tag)
7482
}
7583
}
7684

0 commit comments

Comments
 (0)