@visualbravo/zenstack-cache 1.0.0 → 1.0.2

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 CHANGED
@@ -10,11 +10,14 @@
10
10
  <a href="https://www.npmjs.com/package/@visualbravo/zenstack-cache?activeTab=versions">
11
11
  <img alt="NPM Version" src="https://img.shields.io/npm/v/%40visualbravo%2Fzenstack-cache/latest">
12
12
  </a>
13
+ <a href="https://www.npmjs.com/package/@visualbravo/zenstack-cache">
14
+ <img alt="NPM Downloads" src="https://img.shields.io/npm/dm/%40visualbravo%2Fzenstack-cache">
15
+ </a>
13
16
  <a href="https://github.com/visualbravo/zenstack-cache/actions/workflows/build-and-test.yaml?query=branch%3Adev++">
14
17
  <img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/visualbravo/zenstack-cache/build-and-test.yaml">
15
18
  </a>
16
- <a href="https://discord.gg/Ykhr738dUe">
17
- <img alt="Join the ZenStack server" src="https://img.shields.io/discord/1035538056146595961">
19
+ <a href="https://discord.gg/2PaRSu7X">
20
+ <img alt="Join the ZenStack Cache channel" src="https://img.shields.io/discord/1035538056146595961">
18
21
  </a>
19
22
  <a href="https://github.com/visualbravo/zenstack-cache/blob/76a2de03245c26841b04525dd8b424a8799d654c/LICENSE">
20
23
  <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-green">
@@ -131,6 +134,21 @@ const revalidatedPublishedPosts = await client.$cache.revalidation as Post[]
131
134
  > [!NOTE]
132
135
  > 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.
133
136
 
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
+
134
152
  ## License
135
153
 
136
154
  MIT
package/dist/plugin.cjs CHANGED
@@ -49,18 +49,13 @@ function defineCachePlugin(pluginOptions) {
49
49
  status = "hit";
50
50
  return entry.result;
51
51
  } else if (require_utils.entryIsStale(entry)) {
52
- revalidation = proceed(args).then(async (result$1) => {
53
- try {
54
- await cache.set(key, {
55
- createdAt: Date.now(),
56
- options,
57
- result: result$1
58
- });
59
- return result$1;
60
- } catch (err) {
61
- console.error(`Failed to cache query result: ${err}`);
62
- return null;
63
- }
52
+ revalidation = proceed(args).then((result$1) => {
53
+ cache.set(key, {
54
+ createdAt: Date.now(),
55
+ options,
56
+ result: result$1
57
+ }).catch((err) => console.error(`Failed to cache query result: ${err}`));
58
+ return result$1;
64
59
  });
65
60
  status = "stale";
66
61
  return entry.result;
package/dist/plugin.mjs CHANGED
@@ -47,18 +47,13 @@ function defineCachePlugin(pluginOptions) {
47
47
  status = "hit";
48
48
  return entry.result;
49
49
  } else if (entryIsStale(entry)) {
50
- revalidation = proceed(args).then(async (result$1) => {
51
- try {
52
- await cache.set(key, {
53
- createdAt: Date.now(),
54
- options,
55
- result: result$1
56
- });
57
- return result$1;
58
- } catch (err) {
59
- console.error(`Failed to cache query result: ${err}`);
60
- return null;
61
- }
50
+ revalidation = proceed(args).then((result$1) => {
51
+ cache.set(key, {
52
+ createdAt: Date.now(),
53
+ options,
54
+ result: result$1
55
+ }).catch((err) => console.error(`Failed to cache query result: ${err}`));
56
+ return result$1;
62
57
  });
63
58
  status = "stale";
64
59
  return entry.result;
package/dist/schemas.cjs CHANGED
@@ -4,8 +4,8 @@ zod = require_rolldown_runtime.__toESM(zod);
4
4
 
5
5
  //#region src/schemas.ts
6
6
  const cacheOptionsSchema = zod.default.strictObject({
7
- ttl: zod.default.number().min(1).optional(),
8
- swr: zod.default.number().min(1).optional(),
7
+ ttl: zod.default.int().positive().optional(),
8
+ swr: zod.default.int().positive().optional(),
9
9
  tags: zod.default.string().array().optional()
10
10
  });
11
11
  const cacheEnvelopeSchema = zod.default.object({ cache: cacheOptionsSchema.optional() });
@@ -2,14 +2,14 @@ import z from "zod";
2
2
 
3
3
  //#region src/schemas.d.ts
4
4
  declare const cacheOptionsSchema: z.ZodObject<{
5
- ttl: z.ZodOptional<z.ZodNumber>;
6
- swr: z.ZodOptional<z.ZodNumber>;
5
+ ttl: z.ZodOptional<z.ZodInt>;
6
+ swr: z.ZodOptional<z.ZodInt>;
7
7
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
8
  }, z.core.$strict>;
9
9
  declare const cacheEnvelopeSchema: z.ZodObject<{
10
10
  cache: z.ZodOptional<z.ZodObject<{
11
- ttl: z.ZodOptional<z.ZodNumber>;
12
- swr: z.ZodOptional<z.ZodNumber>;
11
+ ttl: z.ZodOptional<z.ZodInt>;
12
+ swr: z.ZodOptional<z.ZodInt>;
13
13
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
14
  }, z.core.$strict>>;
15
15
  }, z.core.$strip>;
@@ -2,14 +2,14 @@ import z from "zod";
2
2
 
3
3
  //#region src/schemas.d.ts
4
4
  declare const cacheOptionsSchema: z.ZodObject<{
5
- ttl: z.ZodOptional<z.ZodNumber>;
6
- swr: z.ZodOptional<z.ZodNumber>;
5
+ ttl: z.ZodOptional<z.ZodInt>;
6
+ swr: z.ZodOptional<z.ZodInt>;
7
7
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
8
  }, z.core.$strict>;
9
9
  declare const cacheEnvelopeSchema: z.ZodObject<{
10
10
  cache: z.ZodOptional<z.ZodObject<{
11
- ttl: z.ZodOptional<z.ZodNumber>;
12
- swr: z.ZodOptional<z.ZodNumber>;
11
+ ttl: z.ZodOptional<z.ZodInt>;
12
+ swr: z.ZodOptional<z.ZodInt>;
13
13
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
14
  }, z.core.$strict>>;
15
15
  }, z.core.$strip>;
package/dist/schemas.mjs CHANGED
@@ -2,8 +2,8 @@ import z from "zod";
2
2
 
3
3
  //#region src/schemas.ts
4
4
  const cacheOptionsSchema = z.strictObject({
5
- ttl: z.number().min(1).optional(),
6
- swr: z.number().min(1).optional(),
5
+ ttl: z.int().positive().optional(),
6
+ swr: z.int().positive().optional(),
7
7
  tags: z.string().array().optional()
8
8
  });
9
9
  const cacheEnvelopeSchema = z.object({ cache: cacheOptionsSchema.optional() });
package/package.json CHANGED
@@ -1,12 +1,20 @@
1
1
  {
2
2
  "name": "@visualbravo/zenstack-cache",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "repository": "github:visualbravo/zenstack-cache",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.cts",
10
+ "keywords": [
11
+ "zenstack",
12
+ "cache",
13
+ "caching",
14
+ "prisma",
15
+ "accelerate",
16
+ "orm"
17
+ ],
10
18
  "exports": {
11
19
  ".": {
12
20
  "@zenstack-cache/source": "./src/index.ts",