Skip to content

Commit a0d78d2

Browse files
committed
fix: clean up cache by removing missing keys.
1 parent c99b62a commit a0d78d2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ export class CoreFlagsManager implements FlagsManager {
301301
const ttl = this.config.cacheTtl ?? 60_000;
302302
const staleTime = this.config.staleTime ?? ttl / 2;
303303

304+
const existingKeys = Array.from(this.cache.keys());
305+
const missingKeys = existingKeys.filter((key) => !flags[key]);
306+
for (const key of missingKeys) {
307+
this.cache.delete(key);
308+
}
309+
304310
for (const [key, result] of Object.entries(flags)) {
305311
const cacheKey = getCacheKey(key, user ?? this.config.user);
306312
this.cache.set(cacheKey, createCacheEntry(result, ttl, staleTime));

0 commit comments

Comments
 (0)