From 271a26f2b2edea1fb9d4a0f25c17aac10f905cca Mon Sep 17 00:00:00 2001 From: Hidekazu Kobayashi Date: Fri, 6 Oct 2023 22:00:00 +0900 Subject: [PATCH 1/3] Write-back value in memory when it's available in redis --- packages/backend/src/misc/cache.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index 046d4d6c2f6c..b0d6fe049ed5 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -166,6 +166,7 @@ export class RedisSingleCache { const cachedValue = await this.get(); if (cachedValue !== undefined) { // Cache HIT + this.memoryCache.set(cachedValue); return cachedValue; } From 9b9d546ed479021c655cc98f3455f4ace246501e Mon Sep 17 00:00:00 2001 From: Hidekazu Kobayashi Date: Fri, 6 Oct 2023 22:15:38 +0900 Subject: [PATCH 2/3] Fix recursive cache --- packages/backend/src/misc/cache.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index b0d6fe049ed5..2c8b5cb4c1b5 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -149,7 +149,9 @@ export class RedisSingleCache { const cached = await this.redisClient.get(`singlecache:${this.name}`); if (cached == null) return undefined; - return this.fromRedisConverter(cached); + const parsed = this.fromRedisConverter(cached); + this.memoryCache.set(parsed); + return parsed; } @bindThis @@ -166,7 +168,6 @@ export class RedisSingleCache { const cachedValue = await this.get(); if (cachedValue !== undefined) { // Cache HIT - this.memoryCache.set(cachedValue); return cachedValue; } From 53b003a9e2d7b99476c50091df9033e68e7dbf43 Mon Sep 17 00:00:00 2001 From: Hidekazu Kobayashi Date: Fri, 6 Oct 2023 22:23:36 +0900 Subject: [PATCH 3/3] Fix bug in case that invalid data in redis cache --- packages/backend/src/misc/cache.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index 2c8b5cb4c1b5..5b841fbaa191 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -150,6 +150,7 @@ export class RedisSingleCache { const cached = await this.redisClient.get(`singlecache:${this.name}`); if (cached == null) return undefined; const parsed = this.fromRedisConverter(cached); + if (parsed == null) return undefined; this.memoryCache.set(parsed); return parsed; }