@knaus94/prisma-extension-cache-manager 1.3.3 → 1.3.5

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/dist/index.js +14 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -54,7 +54,7 @@ async function main() {
54
54
  });
55
55
  await prisma.user.create({
56
56
  data: {},
57
- unchace: `user_count`, // delete key from cache
57
+ uncache: `user_count`, // delete key from cache
58
58
  });
59
59
  await prisma.user.create({
60
60
  data: {},
@@ -62,7 +62,7 @@ async function main() {
62
62
  ttl: 2000,
63
63
  key: (result) => `user-${user.id}`, // custom cache key by result (There will be no reading from the cache, only a write down)
64
64
  },
65
- unchace: [`user_count`, `users`], // delete keys from cache
65
+ uncache: [`user_count`, `users`], // delete keys from cache
66
66
  });
67
67
  }
68
68
 
package/dist/index.js CHANGED
@@ -10,13 +10,13 @@ function generateComposedKey(options) {
10
10
  .digest("hex");
11
11
  return `Prisma@${options.model}@${hash}`;
12
12
  }
13
- function toSerialize(value) {
14
- const serializedResult = (0, bson_1.serialize)({ value });
13
+ function serializeData(data) {
14
+ const serializedResult = (0, bson_1.serialize)({ data });
15
15
  return Buffer.from(serializedResult).toString("base64");
16
16
  }
17
- function toDeserialize(value) {
18
- const binaryData = Buffer.from(value, "base64");
19
- return (0, bson_1.deserialize)(binaryData).value;
17
+ function deserializeData(data) {
18
+ const binaryData = Buffer.from(data, "base64");
19
+ return (0, bson_1.deserialize)(binaryData).data;
20
20
  }
21
21
  exports.default = ({ cache, serialize }) => {
22
22
  return extension_1.Prisma.defineExtension({
@@ -80,7 +80,7 @@ exports.default = ({ cache, serialize }) => {
80
80
  const cached = await cache.get(cacheKey);
81
81
  if (cached) {
82
82
  if (isBinarySerialize) {
83
- return toDeserialize(cached);
83
+ return deserializeData(cached);
84
84
  }
85
85
  return typeof cached === "string" ? JSON.parse(cached) : cached;
86
86
  }
@@ -89,7 +89,9 @@ exports.default = ({ cache, serialize }) => {
89
89
  if (useUncache)
90
90
  processUncache(result);
91
91
  const ttl = typeof cacheOption === "number" ? cacheOption : undefined;
92
- await cache.set(cacheKey, isBinarySerialize ? toSerialize(result) : JSON.stringify(result), ttl);
92
+ await cache.set(cacheKey, isBinarySerialize
93
+ ? serializeData(result)
94
+ : JSON.stringify(result), ttl);
93
95
  return result;
94
96
  }
95
97
  const { key, ttl } = cacheOption;
@@ -98,7 +100,9 @@ exports.default = ({ cache, serialize }) => {
98
100
  if (useUncache)
99
101
  processUncache(result);
100
102
  const customCacheKey = key(result);
101
- await cache.set(customCacheKey, isBinarySerialize ? toSerialize(result) : JSON.stringify(result), ttl);
103
+ await cache.set(customCacheKey, isBinarySerialize
104
+ ? serializeData(result)
105
+ : JSON.stringify(result), ttl);
102
106
  return result;
103
107
  }
104
108
  const customCacheKey = key ||
@@ -110,7 +114,7 @@ exports.default = ({ cache, serialize }) => {
110
114
  const cached = await cache.get(customCacheKey);
111
115
  if (cached) {
112
116
  if (isBinarySerialize) {
113
- return toDeserialize(cached);
117
+ return deserializeData(cached);
114
118
  }
115
119
  return typeof cached === "string" ? JSON.parse(cached) : cached;
116
120
  }
@@ -118,7 +122,7 @@ exports.default = ({ cache, serialize }) => {
118
122
  const result = await query(queryArgs);
119
123
  if (useUncache)
120
124
  processUncache(result);
121
- await cache.set(customCacheKey, isBinarySerialize ? toDeserialize(result) : JSON.stringify(result), ttl);
125
+ await cache.set(customCacheKey, isBinarySerialize ? serializeData(result) : JSON.stringify(result), ttl);
122
126
  return result;
123
127
  },
124
128
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knaus94/prisma-extension-cache-manager",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/knaus94/prisma-extension-cache-manager.git"