From caa063b0759b821464793701bf82690001533cf3 Mon Sep 17 00:00:00 2001 From: sanny-io <3054653+sanny-io@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:39:32 -0700 Subject: [PATCH 1/2] fix: Redis `invalidate` not working when there is only 1 entry (#26) --- src/providers/redis.ts | 4 ++-- tests/redis.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/providers/redis.ts b/src/providers/redis.ts index 704eaa4..b58093a 100644 --- a/src/providers/redis.ts +++ b/src/providers/redis.ts @@ -60,7 +60,7 @@ export class RedisCacheProvider implements CacheProvider { }) stream.on('data', async (keys: string[]) => { - if (keys.length > 1) { + if (keys.length > 0) { await this.redis.del(...keys) } }) @@ -81,7 +81,7 @@ export class RedisCacheProvider implements CacheProvider { }) stream.on('data', async (keys: string[]) => { - if (keys.length > 1) { + if (keys.length > 0) { await this.redis.del(...keys) } }) diff --git a/tests/redis.test.ts b/tests/redis.test.ts index a4a8c71..be852d1 100644 --- a/tests/redis.test.ts +++ b/tests/redis.test.ts @@ -1191,4 +1191,40 @@ describe('Cache plugin (redis)', () => { }), ).resolves.toBe(true) }) + + it('invalidates correctly when there is only 1 entry', async () => { + let extDb = db.$use( + defineCachePlugin({ + provider: new RedisCacheProvider({ + url: process.env['REDIS_URL'] as string, + }), + }), + ) + + await extDb.user.create({ + data: { + email: 'test@email.com', + }, + }) + + await extDb.user.exists({ + cache: { + tags: ['user1'], + ttl: 60, + }, + }) + + await extDb.$cache.invalidate({ + tags: ['user1'], + }) + + await extDb.user.exists({ + cache: { + tags: ['user1'], + ttl: 60, + }, + }) + + expect(extDb.$cache.status).toBe('miss') + }) }) From 421d838b03bf2aa1e4e473b9b77bd4df556a24f8 Mon Sep 17 00:00:00 2001 From: sanny-io <3054653+sanny-io@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:49:40 -0700 Subject: [PATCH 2/2] chore: bump version to 1.0.8 (#27) --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cad5a9c..847242a 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ const revalidatedPublishedPosts = await client.$cache.revalidation as Post[] You can cache results forever by specifying neither `ttl` nor `swr`. Such results will always be considered fresh. ```typescript -client.post.findMany({ +await client.post.findMany({ cache: { tags: [`user:${userId}`], }, diff --git a/package.json b/package.json index 5733811..e1fae53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@visualbravo/zenstack-cache", - "version": "1.0.7", + "version": "1.0.8", "description": "Reduce response times and database load with query-level caching integrated with the ZenStack ORM.", "keywords": [ "accelerate",