fix(core): use structuredClone for cache item values to ensure immutability

fixes discover only option disappearing after refreshing
This commit is contained in:
Viren070
2025-07-14 21:07:45 +01:00
parent 00862c0592
commit 465b7a40a3
+5 -2
View File
@@ -152,7 +152,7 @@ export class Cache<K, V> {
if (updateTTL) {
item.lastAccessed = now;
}
return item.value;
return structuredClone(item.value);
}
return undefined;
}
@@ -167,7 +167,10 @@ export class Cache<K, V> {
if (this.cache.size >= this.maxSize) {
this.evict();
}
this.cache.set(key, new CacheItem<V>(value, Date.now(), ttl * 1000));
this.cache.set(
key,
new CacheItem<V>(structuredClone(value), Date.now(), ttl * 1000)
);
}
/**