From 3164f5ceeed2ad0176955a06931c59ae574a311b Mon Sep 17 00:00:00 2001 From: sanny-io Date: Tue, 3 Feb 2026 05:25:52 +0000 Subject: [PATCH 1/2] fix: do not await `cache.set` during stale period --- packages/cache/src/plugin.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/cache/src/plugin.ts b/packages/cache/src/plugin.ts index 7ddcb6d..7e87a2b 100644 --- a/packages/cache/src/plugin.ts +++ b/packages/cache/src/plugin.ts @@ -80,19 +80,16 @@ export function defineCachePlugin(pluginOptions: CachePluginOptions) { status = 'hit' return entry.result } else if (entryIsStale(entry)) { - revalidation = proceed(args).then(async result => { - try { - await cache.set(key, { + revalidation = proceed(args).then(result => { + cache + .set(key, { createdAt: Date.now(), options, result, }) + .catch(err => console.error(`Failed to cache query result: ${err}`)) - return result - } catch (err) { - console.error(`Failed to cache query result: ${err}`) - return null - } + return result }) status = 'stale' @@ -117,4 +114,4 @@ export function defineCachePlugin(pluginOptions: CachePluginOptions) { return proceed(args) }, }) -} +} \ No newline at end of file From 87cceb23484834ddc5674ab5c851b354d0dba96c Mon Sep 17 00:00:00 2001 From: sanny-io Date: Tue, 3 Feb 2026 05:26:14 +0000 Subject: [PATCH 2/2] chore: prepare 1.0.2 release --- README.md | 15 +++++++++++++++ package.json | 2 +- packages/cache/package.json | 11 +++++++++-- packages/config/package.json | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d5efff..d34a6ef 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,21 @@ const revalidatedPublishedPosts = await client.$cache.revalidation as Post[] > [!NOTE] > The total TTL of a cache entry is equal to its `ttl` + `swr`. The `ttl` window comes first, followed by the `swr` window. You can combine the two options to best suit the needs of your application. +## Caching Forever + +You can cache results forever by specifying neither `ttl` nor `swr`. Such results will always be considered fresh. + +```typescript +client.post.findMany({ + cache: { + tags: [`user:${userId}`], + }, +}) +``` + +> [!WARNING] +> Your server may eventually run out of memory if you're not careful about invalidating entries that never expire. + ## License MIT diff --git a/package.json b/package.json index 98cae6c..65624f0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "workspace", "type": "module", - "version": "1.0.1", + "version": "1.0.2", "private": "true", "license": "MIT", "scripts": { diff --git a/packages/cache/package.json b/packages/cache/package.json index 0d840a2..d5208b7 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,13 +1,20 @@ { "name": "@visualbravo/zenstack-cache", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "repository": "github:visualbravo/zenstack-cache", "type": "module", "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.cts", - "keywords": ["zenstack", "cache", "caching", "prisma", "accelerate", "orm"], + "keywords": [ + "zenstack", + "cache", + "caching", + "prisma", + "accelerate", + "orm" + ], "exports": { ".": { "@zenstack-cache/source": "./src/index.ts", diff --git a/packages/config/package.json b/packages/config/package.json index 8e371f4..c032ece 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -1,7 +1,7 @@ { "name": "@zenstack-cache/config", "type": "module", - "version": "1.0.1", + "version": "1.0.2", "private": true, "exports": { "./ts": "./ts.json"