implement QuantumKVCache.add and QuantumKVCache.addMany

This commit is contained in:
Hazelnoot 2025-06-06 02:13:53 -04:00
parent bf1156426e
commit b7624666d6
2 changed files with 84 additions and 0 deletions

View file

@ -565,6 +565,28 @@ export class QuantumKVCache<T> implements Iterable<[key: string, value: T]> {
}
}
/**
* Adds a value to the local memory cache without notifying other process.
* Neither a Redis event nor onSet callback will be fired, as the value has not actually changed.
* This should only be used when the value is known to be current, like after fetching from the database.
*/
@bindThis
public add(key: string, value: T): void {
this.memoryCache.set(key, value);
}
/**
* Adds multiple values to the local memory cache without notifying other process.
* Neither a Redis event nor onSet callback will be fired, as the value has not actually changed.
* This should only be used when the value is known to be current, like after fetching from the database.
*/
@bindThis
public addMany(items: Iterable<[key: string, value: T]>): void {
for (const [key, value] of items) {
this.memoryCache.set(key, value);
}
}
/**
* Gets a value from the local memory cache, or returns undefined if not found.
*/