@knaus94/prisma-extension-cache-manager 1.5.68 → 1.5.69

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/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { ModelExtension, PrismaRedisCacheConfig } from "./types";
4
4
  * @param config - Конфигурация для кеша Redis и TTL по умолчанию.
5
5
  * @returns Prisma расширение.
6
6
  */
7
- declare const _default: ({ cache, debug }: PrismaRedisCacheConfig) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
7
+ declare const _default: ({ cache, debug, ttl: defaultTTL }: PrismaRedisCacheConfig) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
8
8
  $allModels: ModelExtension;
9
9
  }, {}, {
10
10
  $cache: import("cache-manager-ioredis-yet").RedisCache;
package/dist/index.js CHANGED
@@ -130,7 +130,7 @@ function shouldUseUncache(uncacheOption) {
130
130
  * @param config - Конфигурация для кеша Redis и TTL по умолчанию.
131
131
  * @returns Prisma расширение.
132
132
  */
133
- exports.default = ({ cache, debug }) => {
133
+ exports.default = ({ cache, debug, ttl: defaultTTL }) => {
134
134
  return extension_1.Prisma.defineExtension({
135
135
  name: "prisma-extension-cache-manager",
136
136
  client: {
@@ -197,10 +197,15 @@ exports.default = ({ cache, debug }) => {
197
197
  // Функция генерирует ключ на основе результатов
198
198
  cacheKey = cacheOption.key(result);
199
199
  ttl = cacheOption.ttl;
200
+ if (ttl === undefined) {
201
+ ttl = defaultTTL;
202
+ }
200
203
  // Сохраняем результат в кеш
201
204
  try {
202
205
  const encoded = serialize(result);
203
- await cache.set(cacheKey, encoded, ttl);
206
+ await (ttl && ttl > 0
207
+ ? cache.store.client.set(cacheKey, encoded, "EX", ttl / 1000)
208
+ : cache.store.client.set(cacheKey, encoded));
204
209
  if (debug) {
205
210
  console.log("Data cached with key (function):", cacheKey, "encoded:", encoded, "decoded:", result);
206
211
  }
@@ -223,9 +228,9 @@ exports.default = ({ cache, debug }) => {
223
228
  if (!isWriteOperation) {
224
229
  try {
225
230
  // Используем getBuffer, т.к. сохраняем бинарные данные
226
- const cached = await cache.get(cacheKey);
231
+ const cached = await cache.store.client.getBuffer(cacheKey);
227
232
  if (cached) {
228
- const data = deserialize(cached.data);
233
+ const data = deserialize(cached);
229
234
  if (debug) {
230
235
  console.log("Cache hit for key:", cacheKey, "data", cached, "decoded", data);
231
236
  }
@@ -249,10 +254,15 @@ exports.default = ({ cache, debug }) => {
249
254
  if (useUncache) {
250
255
  await processUncache(cache, uncacheOption, result);
251
256
  }
257
+ if (ttl === undefined) {
258
+ ttl = defaultTTL;
259
+ }
252
260
  // 6. Сохраняем результат запроса в кеш
253
261
  try {
254
262
  const encoded = serialize(result);
255
- await cache.set(cacheKey, encoded, ttl);
263
+ await (ttl && ttl > 0
264
+ ? cache.store.client.set(cacheKey, encoded, "EX", ttl / 1000)
265
+ : cache.store.client.set(cacheKey, encoded));
256
266
  if (debug) {
257
267
  console.log("Data cached with key:", cacheKey, "encoded:", encoded, "decoded:", result);
258
268
  }
package/dist/types.d.ts CHANGED
@@ -36,5 +36,6 @@ export interface PrismaCacheArgs<T, A, O extends RequiredArgsOperation | Optiona
36
36
  export interface PrismaRedisCacheConfig {
37
37
  cache: RedisCache;
38
38
  debug?: boolean;
39
+ ttl?: number;
39
40
  }
40
41
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knaus94/prisma-extension-cache-manager",
3
- "version": "1.5.68",
3
+ "version": "1.5.69",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/knaus94/prisma-extension-cache-manager.git"