summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-06-06 02:13:53 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-09 11:02:36 -0400
commitb7624666d65d96e9b9db62439a164e9625883c55 (patch)
tree383b9f49c08e80c0319650b7a993621ee7181443 /packages/backend/src
parentadd CacheService.getUserFollowings and CacheService.getUserBlockers (diff)
downloadsharkey-b7624666d65d96e9b9db62439a164e9625883c55.tar.gz
sharkey-b7624666d65d96e9b9db62439a164e9625883c55.tar.bz2
sharkey-b7624666d65d96e9b9db62439a164e9625883c55.zip
implement QuantumKVCache.add and QuantumKVCache.addMany
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/misc/cache.ts22
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