summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CacheService.ts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-08-06 16:51:18 +0000
committerdakkar <dakkar@thenautilus.net>2024-08-06 16:51:18 +0000
commit4e7df7a5f21f91d49318840600fe329cae05c919 (patch)
tree701cdaa4a1ae06412d86fc98529aa45ae26ae190 /packages/backend/src/core/CacheService.ts
parentmerge: Add icon for moving files/folders - for !583 (!586) (diff)
parentFix timeout comments (diff)
downloadsharkey-4e7df7a5f21f91d49318840600fe329cae05c919.tar.gz
sharkey-4e7df7a5f21f91d49318840600fe329cae05c919.tar.bz2
sharkey-4e7df7a5f21f91d49318840600fe329cae05c919.zip
merge: Remove infinite caches to prevent memory leak (!587)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/587 Closes #600 and #601 Approved-by: Amelia Yukii <amelia.yukii@shourai.de> Approved-by: Marie <marie@kaifa.ch>
Diffstat (limited to 'packages/backend/src/core/CacheService.ts')
-rw-r--r--packages/backend/src/core/CacheService.ts12
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);
}