diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-06-06 02:13:53 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-06-09 11:02:36 -0400 |
| commit | b7624666d65d96e9b9db62439a164e9625883c55 (patch) | |
| tree | 383b9f49c08e80c0319650b7a993621ee7181443 /packages/backend/src/misc | |
| parent | add CacheService.getUserFollowings and CacheService.getUserBlockers (diff) | |
| download | sharkey-b7624666d65d96e9b9db62439a164e9625883c55.tar.gz sharkey-b7624666d65d96e9b9db62439a164e9625883c55.tar.bz2 sharkey-b7624666d65d96e9b9db62439a164e9625883c55.zip | |
implement QuantumKVCache.add and QuantumKVCache.addMany
Diffstat (limited to 'packages/backend/src/misc')
| -rw-r--r-- | packages/backend/src/misc/cache.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index 22201e243f..3145550a44 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -566,6 +566,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. */ @bindThis |