Skip to content

Commit ef8caa0

Browse files
committed
feat: Remove stale cache keys for flags.
1 parent 34f00c2 commit ef8caa0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/sdk/src/core/flags/flags-manager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ export class CoreFlagsManager implements FlagsManager {
106106
};
107107
}
108108

109+
private removeStaleKeys(validCacheKeys: Set<string>): void {
110+
for (const key of this.cache.keys()) {
111+
if (!validCacheKeys.has(key)) {
112+
this.cache.delete(key);
113+
}
114+
}
115+
}
116+
109117
private async initialize(): Promise<void> {
110118
// Load from persistent storage first (instant hydration)
111119
if (!this.config.skipStorage && this.storage) {
@@ -304,6 +312,10 @@ export class CoreFlagsManager implements FlagsManager {
304312
cacheEntry: createCacheEntry(result, ttl, staleTime),
305313
}));
306314

315+
this.removeStaleKeys(
316+
new Set(flagCacheEntries.map(({ cacheKey }) => cacheKey))
317+
);
318+
307319
for (const { cacheKey, cacheEntry } of flagCacheEntries) {
308320
this.cache.set(cacheKey, cacheEntry);
309321
}

0 commit comments

Comments
 (0)