From f6ab7efa3df04b68f5793536809899bfb56a8508 Mon Sep 17 00:00:00 2001 From: sanny-io Date: Tue, 3 Feb 2026 04:54:51 +0000 Subject: [PATCH 1/3] fix: do not await `cache.set` during stale period --- packages/cache/src/plugin.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/cache/src/plugin.ts b/packages/cache/src/plugin.ts index 7ddcb6d..3147f66 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' From ae356f58c58d3422c90d814f0f9a5b957762456e Mon Sep 17 00:00:00 2001 From: sanny-io Date: Tue, 3 Feb 2026 04:55:25 +0000 Subject: [PATCH 2/3] docs: add caching forever section to README and warn about memory usage --- README.md | 15 +++++++++++++++ packages/cache/package.json | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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/packages/cache/package.json b/packages/cache/package.json index 0d840a2..0690525 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -7,7 +7,14 @@ "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", From c27933a7656535e5904bbcbf3e58763718e8c37a Mon Sep 17 00:00:00 2001 From: sanny-io Date: Tue, 3 Feb 2026 05:00:33 +0000 Subject: [PATCH 3/3] fix: update package versions to 1.0.2 --- package.json | 2 +- packages/cache/package.json | 2 +- packages/config/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 0690525..d5208b7 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@visualbravo/zenstack-cache", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "repository": "github:visualbravo/zenstack-cache", "type": "module", 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"