@visualbravo/zenstack-cache 1.0.5 â 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -15
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.d.cts +2 -2
- package/dist/plugin.d.mts +2 -2
- package/dist/plugin.mjs +1 -1
- package/package.json +15 -4
package/README.md
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
ZenStack Cache
|
|
4
4
|
</h1>
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Reduce response times and database load with query-level caching integrated with the ZenStack ORM.
|
|
7
|
+
|
|
7
8
|
</div>
|
|
8
9
|
|
|
9
10
|
<div align="center">
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
<a href="https://discord.gg/2PaRSu7X">
|
|
20
21
|
<img alt="Join the ZenStack Cache channel" src="https://img.shields.io/discord/1035538056146595961">
|
|
21
22
|
</a>
|
|
22
|
-
<a href="https://github.com/visualbravo/zenstack-cache/blob/
|
|
23
|
+
<a href="https://github.com/visualbravo/zenstack-cache/blob/dev/LICENSE">
|
|
23
24
|
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-green">
|
|
24
25
|
</a>
|
|
25
26
|
|
|
@@ -29,17 +30,18 @@
|
|
|
29
30
|
</div>
|
|
30
31
|
|
|
31
32
|
## Features
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
|
|
34
|
+
- đ **Redis Cache:** A central cache to scale across different systems.
|
|
35
|
+
- đĨī¸ **Memory Cache:** A simple cache when scale is not a concern.
|
|
36
|
+
- đ **Type-safety:** The caching options appear in the intellisense for all read queries.
|
|
37
|
+
- đˇī¸ **Tag-based Invalidation:** Easily invalidate multiple related cache entries.
|
|
36
38
|
|
|
37
39
|
## Requirements
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
- ZenStack (version >= `3.3.0`)
|
|
42
|
+
- Node.js (version >= `20.0.0`)
|
|
43
|
+
- Redis (version >= `7.0.0`)
|
|
44
|
+
- âšī¸ Only if you intend to use the `RedisCacheProvider`
|
|
43
45
|
|
|
44
46
|
## Installation
|
|
45
47
|
|
|
@@ -115,21 +117,22 @@ After performing a query, you can check where the result came from.
|
|
|
115
117
|
const publishedPostsStatus = client.$cache.status // 'hit' | 'miss' | 'stale'
|
|
116
118
|
```
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
- `hit` - a cache entry in the `ttl` window was found, and the database was not queried.
|
|
121
|
+
- `miss` - a cache entry was not found, and the database was queried.
|
|
122
|
+
- `stale` - a cache entry in the `swr` window was found, and the database was queried in the background to revalidate it.
|
|
121
123
|
|
|
122
124
|
## Revalidation
|
|
123
125
|
|
|
124
126
|
If the result was stale, you can choose to await its revalidation.
|
|
127
|
+
|
|
125
128
|
```typescript
|
|
126
129
|
const revalidatedPublishedPosts = await client.$cache.revalidation as Post[]
|
|
127
130
|
```
|
|
128
131
|
|
|
129
132
|
## Cache Options
|
|
130
133
|
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
- `ttl` reduces response times and database load by serving cached results.
|
|
135
|
+
- `swr` reduces response times by serving cached results, but does not reduce database load because it performs a revalidation in the background after each request.
|
|
133
136
|
|
|
134
137
|
> [!NOTE]
|
|
135
138
|
> 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.
|
package/dist/plugin.cjs
CHANGED
|
@@ -38,7 +38,7 @@ function defineCachePlugin(pluginOptions) {
|
|
|
38
38
|
args,
|
|
39
39
|
model,
|
|
40
40
|
operation,
|
|
41
|
-
authId: client.$auth ?
|
|
41
|
+
authId: client.$auth ? client.$schema.models[client.$schema.authType].idFields.map((key$1) => client.$auth[key$1]) : void 0
|
|
42
42
|
});
|
|
43
43
|
if (!json) throw new Error(`Failed to serialize cache entry for ${lowerCaseFirst(model)}.${operation}`);
|
|
44
44
|
const cache = pluginOptions.provider;
|
package/dist/plugin.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CacheInvalidationOptions, CachePluginOptions, CacheStatus } from "./types.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _zenstackhq_orm0 from "@zenstackhq/orm";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin.d.ts
|
|
5
|
-
declare function defineCachePlugin(pluginOptions: CachePluginOptions):
|
|
5
|
+
declare function defineCachePlugin(pluginOptions: CachePluginOptions): _zenstackhq_orm0.RuntimePlugin<any, {
|
|
6
6
|
readonly $read: {
|
|
7
7
|
cache?: {
|
|
8
8
|
ttl?: number | undefined;
|
package/dist/plugin.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CacheInvalidationOptions, CachePluginOptions, CacheStatus } from "./types.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _zenstackhq_orm0 from "@zenstackhq/orm";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin.d.ts
|
|
5
|
-
declare function defineCachePlugin(pluginOptions: CachePluginOptions):
|
|
5
|
+
declare function defineCachePlugin(pluginOptions: CachePluginOptions): _zenstackhq_orm0.RuntimePlugin<any, {
|
|
6
6
|
readonly $read: {
|
|
7
7
|
cache?: {
|
|
8
8
|
ttl?: number | undefined;
|
package/dist/plugin.mjs
CHANGED
|
@@ -36,7 +36,7 @@ function defineCachePlugin(pluginOptions) {
|
|
|
36
36
|
args,
|
|
37
37
|
model,
|
|
38
38
|
operation,
|
|
39
|
-
authId: client.$auth ?
|
|
39
|
+
authId: client.$auth ? client.$schema.models[client.$schema.authType].idFields.map((key$1) => client.$auth[key$1]) : void 0
|
|
40
40
|
});
|
|
41
41
|
if (!json) throw new Error(`Failed to serialize cache entry for ${lowerCaseFirst(model)}.${operation}`);
|
|
42
42
|
const cache = pluginOptions.provider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visualbravo/zenstack-cache",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "Reduce response times and database load with query-level caching integrated with the ZenStack ORM.",
|
|
4
5
|
"keywords": [
|
|
5
6
|
"accelerate",
|
|
6
7
|
"cache",
|
|
@@ -12,6 +13,10 @@
|
|
|
12
13
|
"typescript",
|
|
13
14
|
"zenstack"
|
|
14
15
|
],
|
|
16
|
+
"homepage": "https://github.com/visualbravo/zenstack-cache",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/visualbravo/zenstack-cache/issues"
|
|
19
|
+
},
|
|
15
20
|
"license": "MIT",
|
|
16
21
|
"repository": "github:visualbravo/zenstack-cache",
|
|
17
22
|
"type": "module",
|
|
@@ -117,12 +122,18 @@
|
|
|
117
122
|
},
|
|
118
123
|
"devDependencies": {
|
|
119
124
|
"@types/better-sqlite3": "7.6.13",
|
|
120
|
-
"@
|
|
125
|
+
"@types/bun": "1.3.8",
|
|
126
|
+
"@types/node": "20.19.6",
|
|
121
127
|
"better-sqlite3": "12.6.2",
|
|
122
|
-
"kysely": "
|
|
128
|
+
"kysely": "0.28.8",
|
|
129
|
+
"oxfmt": "0.20.0",
|
|
130
|
+
"oxlint": "1.35.0",
|
|
131
|
+
"tsdown": "0.18.3",
|
|
132
|
+
"typescript": "5.9.3",
|
|
133
|
+
"vitest": "4.0.17"
|
|
123
134
|
},
|
|
124
135
|
"peerDependencies": {
|
|
125
|
-
"@zenstackhq/orm": "
|
|
136
|
+
"@zenstackhq/orm": "^3.3.0"
|
|
126
137
|
},
|
|
127
138
|
"packageManager": "bun@1.3.8"
|
|
128
139
|
}
|