Skip to content

Commit 17affe8

Browse files
authored
chore: merge dev to main (1.0.2) (#9)
2 parents 824ff4e + 18e1693 commit 17affe8

5 files changed

Lines changed: 32 additions & 13 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ const revalidatedPublishedPosts = await client.$cache.revalidation as Post[]
134134
> [!NOTE]
135135
> 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.
136136
137+
## Caching Forever
138+
139+
You can cache results forever by specifying neither `ttl` nor `swr`. Such results will always be considered fresh.
140+
141+
```typescript
142+
client.post.findMany({
143+
cache: {
144+
tags: [`user:${userId}`],
145+
},
146+
})
147+
```
148+
149+
> [!WARNING]
150+
> Your server may eventually run out of memory if you're not careful about invalidating entries that never expire.
151+
137152
## License
138153

139154
MIT

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "workspace",
33
"type": "module",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"private": "true",
66
"license": "MIT",
77
"scripts": {

packages/cache/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
{
22
"name": "@visualbravo/zenstack-cache",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"license": "MIT",
55
"repository": "github:visualbravo/zenstack-cache",
66
"type": "module",
77
"main": "./dist/index.cjs",
88
"module": "./dist/index.mjs",
99
"types": "./dist/index.d.cts",
10-
"keywords": ["zenstack", "cache", "caching", "prisma", "accelerate", "orm"],
10+
"keywords": [
11+
"zenstack",
12+
"cache",
13+
"caching",
14+
"prisma",
15+
"accelerate",
16+
"orm"
17+
],
1118
"exports": {
1219
".": {
1320
"@zenstack-cache/source": "./src/index.ts",

packages/cache/src/plugin.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,16 @@ export function defineCachePlugin(pluginOptions: CachePluginOptions) {
8080
status = 'hit'
8181
return entry.result
8282
} else if (entryIsStale(entry)) {
83-
revalidation = proceed(args).then(async result => {
84-
try {
85-
await cache.set(key, {
83+
revalidation = proceed(args).then(result => {
84+
cache
85+
.set(key, {
8686
createdAt: Date.now(),
8787
options,
8888
result,
8989
})
90+
.catch(err => console.error(`Failed to cache query result: ${err}`))
9091

91-
return result
92-
} catch (err) {
93-
console.error(`Failed to cache query result: ${err}`)
94-
return null
95-
}
92+
return result
9693
})
9794

9895
status = 'stale'
@@ -117,4 +114,4 @@ export function defineCachePlugin(pluginOptions: CachePluginOptions) {
117114
return proceed(args)
118115
},
119116
})
120-
}
117+
}

packages/config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstack-cache/config",
33
"type": "module",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"private": true,
66
"exports": {
77
"./ts": "./ts.json"

0 commit comments

Comments
 (0)