@knaus94/prisma-extension-cache-manager 1.5.4 → 1.5.51

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 (2) hide show
  1. package/dist/index.js +13 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -56,6 +56,12 @@ function generateComposedKey(options) {
56
56
  function createKey(key, namespace) {
57
57
  return namespace ? `${namespace}:${key}` : key;
58
58
  }
59
+ function serialize(data) {
60
+ return mp.encode({ data });
61
+ }
62
+ function deserialize(buffer) {
63
+ return mp.decode(buffer).data;
64
+ }
59
65
  /**
60
66
  * Обрабатывает удаление ключей из кеша после операций записи.
61
67
  * @param cache - Кеш-менеджер.
@@ -190,7 +196,7 @@ exports.default = ({ cache, defaultTTL, debug }) => {
190
196
  ttl = cacheOption.ttl ?? defaultTTL;
191
197
  // Сохраняем результат в кеш, используя msgpack5
192
198
  try {
193
- await cache.set(cacheKey, mp.encode(result), ttl);
199
+ await cache.set(cacheKey, serialize(result), ttl);
194
200
  if (debug) {
195
201
  console.log("Data cached with key (function):", cacheKey, "encoded:", mp.encode(result), "decoded:", result);
196
202
  }
@@ -215,11 +221,12 @@ exports.default = ({ cache, defaultTTL, debug }) => {
215
221
  // Используем getBuffer, т.к. сохраняем бинарные данные
216
222
  const cached = await cache.store.client.getBuffer(cacheKey);
217
223
  if (cached) {
224
+ const data = deserialize(cached);
218
225
  if (debug) {
219
- console.log("Cache hit for key:", cacheKey, "data", cached);
226
+ console.log("Cache hit for key:", cacheKey, "data", cached, "decoded", data);
220
227
  }
221
228
  // Десериализуем через msgpack5
222
- return mp.decode(cached);
229
+ return data;
223
230
  }
224
231
  else {
225
232
  if (debug) {
@@ -241,9 +248,10 @@ exports.default = ({ cache, defaultTTL, debug }) => {
241
248
  }
242
249
  // 6. Сохраняем результат запроса в кеш
243
250
  try {
244
- await cache.set(cacheKey, mp.encode(result), ttl);
251
+ const data = serialize(result);
252
+ await cache.set(cacheKey, data, ttl);
245
253
  if (debug) {
246
- console.log("Data cached with key:", cacheKey);
254
+ console.log("Data cached with key:", cacheKey, "encoded:", data, "decoded:", result);
247
255
  }
248
256
  }
249
257
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knaus94/prisma-extension-cache-manager",
3
- "version": "1.5.4",
3
+ "version": "1.5.51",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/knaus94/prisma-extension-cache-manager.git"