From 90e27c16b782a599eb77f9d8825746ad3832fc3b Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Sat, 11 Nov 2023 11:54:04 +0100 Subject: [PATCH] feat(enmeshed): Set cache ttl to 20min --- packages/server/src/internals/cache/index.ts | 8 +++++++- .../server/src/internals/server/enmeshed-middleware.ts | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/server/src/internals/cache/index.ts b/packages/server/src/internals/cache/index.ts index bd1354035..7ad4a2209 100644 --- a/packages/server/src/internals/cache/index.ts +++ b/packages/server/src/internals/cache/index.ts @@ -34,6 +34,7 @@ export interface Cache { payload: { key: string source: string + ttlInSeconds?: number priority?: Priority } & FunctionOrValue, ): Promise @@ -62,9 +63,10 @@ export function createCache({ timer }: { timer: Timer }): Cache { key: string source: string priority?: Priority + ttlInSeconds?: number } & FunctionOrValue, ) { - const { key, priority = Priority.High, source } = payload + const { key, priority = Priority.High, source, ttlInSeconds } = payload const lockManager = lockManagers[priority] const lock = await lockManager.lock(key) @@ -92,6 +94,10 @@ export function createCache({ timer }: { timer: Timer }): Cache { } const packedValue = msgpack.encode(valueWithTimestamp) await client.set(key, packedValue) + + if (ttlInSeconds != null) { + await client.expire(key, ttlInSeconds) + } } catch (e) { log.error(`Failed to set key "${key}":`, e) throw e diff --git a/packages/server/src/internals/server/enmeshed-middleware.ts b/packages/server/src/internals/server/enmeshed-middleware.ts index 38d5e4d7b..74a67d987 100644 --- a/packages/server/src/internals/server/enmeshed-middleware.ts +++ b/packages/server/src/internals/server/enmeshed-middleware.ts @@ -657,12 +657,14 @@ async function setSession( await cache.set({ key: getSessionKey(sessionId), value: session, + ttlInSeconds: 20 * 60, source: 'enmeshed-middleware', }) if (session.enmeshedId) { await cache.set({ key: getIdentityKey(session.enmeshedId), value: sessionId, + ttlInSeconds: 20 * 60, source: 'enmeshed-middleware', }) }