@visualbravo/zenstack-cache 1.0.1 → 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
@@ -134,6 +134,21 @@ const revalidatedPublishedPosts = await client.$cache.revalidation as Post[]
134
134
  > [!NOTE]
135
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.
136
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
+
137
152
  ## License
138
153
 
139
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visualbravo/zenstack-cache",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "repository": "github:visualbravo/zenstack-cache",
6
6
  "type": "module",