diff --git a/packages/backend-core/src/cache/base/index.ts b/packages/backend-core/src/cache/base/index.ts index 942d70ae72..a712ddc263 100644 --- a/packages/backend-core/src/cache/base/index.ts +++ b/packages/backend-core/src/cache/base/index.ts @@ -108,4 +108,13 @@ export default class BaseCache { throw err } } + + /** + * Delete the entry if the provided value matches the stored one. + */ + async deleteIfValue(key: string, value: any, opts = { useTenancy: true }) { + key = opts.useTenancy ? generateTenantKey(key) : key + const client = await this.getClient() + await client.deleteIfValue(key, value) + } } diff --git a/packages/backend-core/src/cache/docWritethrough.ts b/packages/backend-core/src/cache/docWritethrough.ts index 5454362343..e8e0e7beb3 100644 --- a/packages/backend-core/src/cache/docWritethrough.ts +++ b/packages/backend-core/src/cache/docWritethrough.ts @@ -66,6 +66,11 @@ docWritethroughProcessorQueue.process(async message => { await persistToDb(cache, message.data) console.log("DocWritethrough persisted", { data: message.data }) + + await cache.deleteIfValue( + REDIS_KEYS(cacheKeyPrefix).LATEST_MESSAGE_ID, + latestMessageId + ) } )