diff options
| author | Hazel K <acomputerdog@gmail.com> | 2024-08-18 00:34:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-18 13:34:01 +0900 |
| commit | 9ce44b24b8837b846e3170c70da13f8d0f86d581 (patch) | |
| tree | f463bdf7435c9881160c59d4e1ec034dd034c033 /packages/backend/src/core/CacheService.ts | |
| parent | Merge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff) | |
| download | sharkey-9ce44b24b8837b846e3170c70da13f8d0f86d581.tar.gz sharkey-9ce44b24b8837b846e3170c70da13f8d0f86d581.tar.bz2 sharkey-9ce44b24b8837b846e3170c70da13f8d0f86d581.zip | |
fix(backend): memory leak in memory caches (#14363)
* encapsulate `MemoryKVCache<T>`
* remove infinity caches
* encapsulate other caches
* add missing awaits to internally synchronize caches
* implement pull-through caching
* tune cache lifetimes
* optimize cache GC by stopping early
* summarize changes in CHANGELOG.md
* Fix timeout comments
Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
* add comments about awaiting the redis write
---------
Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Diffstat (limited to 'packages/backend/src/core/CacheService.ts')
| -rw-r--r-- | packages/backend/src/core/CacheService.ts | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts index d008e7ec52..6725ebe75b 100644 --- a/packages/backend/src/core/CacheService.ts +++ b/packages/backend/src/core/CacheService.ts @@ -56,10 +56,10 @@ export class CacheService implements OnApplicationShutdown { ) { //this.onMessage = this.onMessage.bind(this); - this.userByIdCache = new MemoryKVCache<MiUser>(Infinity); - this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null>(Infinity); - this.localUserByIdCache = new MemoryKVCache<MiLocalUser>(Infinity); - this.uriPersonCache = new MemoryKVCache<MiUser | null>(Infinity); + this.userByIdCache = new MemoryKVCache<MiUser>(1000 * 60 * 5); // 5m + this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null>(1000 * 60 * 5); // 5m + this.localUserByIdCache = new MemoryKVCache<MiLocalUser>(1000 * 60 * 5); // 5m + this.uriPersonCache = new MemoryKVCache<MiUser | null>(1000 * 60 * 5); // 5m this.userProfileCache = new RedisKVCache<MiUserProfile>(this.redisClient, 'userProfile', { lifetime: 1000 * 60 * 30, // 30m @@ -135,14 +135,14 @@ export class CacheService implements OnApplicationShutdown { if (user == null) { this.userByIdCache.delete(body.id); this.localUserByIdCache.delete(body.id); - for (const [k, v] of this.uriPersonCache.cache.entries()) { + for (const [k, v] of this.uriPersonCache.entries) { if (v.value?.id === body.id) { this.uriPersonCache.delete(k); } } } else { this.userByIdCache.set(user.id, user); - for (const [k, v] of this.uriPersonCache.cache.entries()) { + for (const [k, v] of this.uriPersonCache.entries) { if (v.value?.id === user.id) { this.uriPersonCache.set(k, user); } |