ts-cache-mongoose 1.7.0 → 1.7.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.
Files changed (90) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -9
  3. package/biome.json +1 -1
  4. package/dist/index.cjs +325 -0
  5. package/dist/{cjs/types/plugin.d.ts → index.d.cts} +22 -4
  6. package/dist/{esm/types/plugin.d.ts → index.d.mts} +22 -4
  7. package/dist/index.mjs +323 -0
  8. package/package.json +37 -32
  9. package/src/extend/aggregate.ts +2 -2
  10. package/src/extend/query.ts +2 -2
  11. package/src/{plugin.ts → index.ts} +2 -0
  12. package/tests/cache-debug.test.ts +2 -3
  13. package/tests/cache-memory.test.ts +2 -3
  14. package/tests/cache-options.test.ts +0 -1
  15. package/tests/cache-redis.test.ts +11 -13
  16. package/tests/key.test.ts +2 -1
  17. package/tsconfig.json +5 -5
  18. package/vite.config.mts +1 -0
  19. package/.swcrc +0 -17
  20. package/dist/cjs/cache/Cache.js +0 -67
  21. package/dist/cjs/cache/Cache.js.map +0 -1
  22. package/dist/cjs/cache/engine/MemoryCacheEngine.js +0 -39
  23. package/dist/cjs/cache/engine/MemoryCacheEngine.js.map +0 -1
  24. package/dist/cjs/cache/engine/RedisCacheEngine.js +0 -54
  25. package/dist/cjs/cache/engine/RedisCacheEngine.js.map +0 -1
  26. package/dist/cjs/extend/aggregate.js +0 -41
  27. package/dist/cjs/extend/aggregate.js.map +0 -1
  28. package/dist/cjs/extend/query.js +0 -67
  29. package/dist/cjs/extend/query.js.map +0 -1
  30. package/dist/cjs/key.js +0 -14
  31. package/dist/cjs/key.js.map +0 -1
  32. package/dist/cjs/plugin.js +0 -36
  33. package/dist/cjs/plugin.js.map +0 -1
  34. package/dist/cjs/types/cache/Cache.d.ts +0 -11
  35. package/dist/cjs/types/cache/Cache.d.ts.map +0 -1
  36. package/dist/cjs/types/cache/engine/MemoryCacheEngine.d.ts +0 -11
  37. package/dist/cjs/types/cache/engine/MemoryCacheEngine.d.ts.map +0 -1
  38. package/dist/cjs/types/cache/engine/RedisCacheEngine.d.ts +0 -12
  39. package/dist/cjs/types/cache/engine/RedisCacheEngine.d.ts.map +0 -1
  40. package/dist/cjs/types/extend/aggregate.d.ts +0 -4
  41. package/dist/cjs/types/extend/aggregate.d.ts.map +0 -1
  42. package/dist/cjs/types/extend/query.d.ts +0 -4
  43. package/dist/cjs/types/extend/query.d.ts.map +0 -1
  44. package/dist/cjs/types/key.d.ts +0 -2
  45. package/dist/cjs/types/key.d.ts.map +0 -1
  46. package/dist/cjs/types/plugin.d.ts.map +0 -1
  47. package/dist/cjs/types/types.d.ts +0 -18
  48. package/dist/cjs/types/types.d.ts.map +0 -1
  49. package/dist/cjs/types/version.d.ts +0 -6
  50. package/dist/cjs/types/version.d.ts.map +0 -1
  51. package/dist/cjs/types.js +0 -3
  52. package/dist/cjs/types.js.map +0 -1
  53. package/dist/cjs/version.js +0 -20
  54. package/dist/cjs/version.js.map +0 -1
  55. package/dist/esm/cache/Cache.js +0 -63
  56. package/dist/esm/cache/Cache.js.map +0 -1
  57. package/dist/esm/cache/engine/MemoryCacheEngine.js +0 -35
  58. package/dist/esm/cache/engine/MemoryCacheEngine.js.map +0 -1
  59. package/dist/esm/cache/engine/RedisCacheEngine.js +0 -50
  60. package/dist/esm/cache/engine/RedisCacheEngine.js.map +0 -1
  61. package/dist/esm/extend/aggregate.js +0 -38
  62. package/dist/esm/extend/aggregate.js.map +0 -1
  63. package/dist/esm/extend/query.js +0 -64
  64. package/dist/esm/extend/query.js.map +0 -1
  65. package/dist/esm/key.js +0 -10
  66. package/dist/esm/key.js.map +0 -1
  67. package/dist/esm/package.json +0 -1
  68. package/dist/esm/plugin.js +0 -34
  69. package/dist/esm/plugin.js.map +0 -1
  70. package/dist/esm/types/cache/Cache.d.ts +0 -11
  71. package/dist/esm/types/cache/Cache.d.ts.map +0 -1
  72. package/dist/esm/types/cache/engine/MemoryCacheEngine.d.ts +0 -11
  73. package/dist/esm/types/cache/engine/MemoryCacheEngine.d.ts.map +0 -1
  74. package/dist/esm/types/cache/engine/RedisCacheEngine.d.ts +0 -12
  75. package/dist/esm/types/cache/engine/RedisCacheEngine.d.ts.map +0 -1
  76. package/dist/esm/types/extend/aggregate.d.ts +0 -4
  77. package/dist/esm/types/extend/aggregate.d.ts.map +0 -1
  78. package/dist/esm/types/extend/query.d.ts +0 -4
  79. package/dist/esm/types/extend/query.d.ts.map +0 -1
  80. package/dist/esm/types/key.d.ts +0 -2
  81. package/dist/esm/types/key.d.ts.map +0 -1
  82. package/dist/esm/types/plugin.d.ts.map +0 -1
  83. package/dist/esm/types/types.d.ts +0 -18
  84. package/dist/esm/types/types.d.ts.map +0 -1
  85. package/dist/esm/types/version.d.ts +0 -6
  86. package/dist/esm/types/version.d.ts.map +0 -1
  87. package/dist/esm/types.js +0 -2
  88. package/dist/esm/types.js.map +0 -1
  89. package/dist/esm/version.js +0 -15
  90. package/dist/esm/version.js.map +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 ilovepixelart
3
+ Copyright (c) 2025 ilovepixelart
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -30,15 +30,15 @@ Caching queries is a good way to improve performance of your application
30
30
 
31
31
  ## Features
32
32
 
33
- - [x] In-memory caching
34
- - [x] Redis caching
35
- - [x] Cache expiration
36
- - [x] Cache invalidation
37
- - [x] Cache key generation
38
- - [x] Cache key prefix
39
- - [x] Query caching
40
- - [x] Aggregate caching
41
- - [x] Supports ESM and CommonJS
33
+ - In-memory caching
34
+ - Redis caching
35
+ - Cache expiration
36
+ - Cache invalidation
37
+ - Cache key generation
38
+ - Cache key prefix
39
+ - Query caching
40
+ - Aggregate caching
41
+ - Supports ESM and CommonJS
42
42
 
43
43
  ## Installation
44
44
 
package/biome.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3
3
  "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4
4
  "files": {
5
5
  "ignoreUnknown": false,
package/dist/index.cjs ADDED
@@ -0,0 +1,325 @@
1
+ 'use strict';
2
+
3
+ var ms = require('ms');
4
+ var bson = require('bson');
5
+ var IORedis = require('ioredis');
6
+ var mongoose = require('mongoose');
7
+ var semver = require('semver');
8
+ var node_crypto = require('node:crypto');
9
+ var sortKeys = require('sort-keys');
10
+
11
+ var __typeError$3 = (msg) => {
12
+ throw TypeError(msg);
13
+ };
14
+ var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
15
+ var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
16
+ var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
17
+ var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
18
+ var _cache;
19
+ class MemoryCacheEngine {
20
+ constructor() {
21
+ __privateAdd$3(this, _cache);
22
+ __privateSet$3(this, _cache, /* @__PURE__ */ new Map());
23
+ }
24
+ get(key) {
25
+ const item = __privateGet$3(this, _cache).get(key);
26
+ if (!item || item.expiresAt < Date.now()) {
27
+ this.del(key);
28
+ return void 0;
29
+ }
30
+ return item.value;
31
+ }
32
+ set(key, value, ttl) {
33
+ const givenTTL = typeof ttl === "string" ? ms(ttl) : ttl;
34
+ const actualTTL = givenTTL ?? Number.POSITIVE_INFINITY;
35
+ __privateGet$3(this, _cache).set(key, {
36
+ value,
37
+ expiresAt: Date.now() + actualTTL
38
+ });
39
+ }
40
+ del(key) {
41
+ __privateGet$3(this, _cache).delete(key);
42
+ }
43
+ clear() {
44
+ __privateGet$3(this, _cache).clear();
45
+ }
46
+ close() {
47
+ }
48
+ }
49
+ _cache = new WeakMap();
50
+
51
+ const isMongooseLessThan7 = semver.satisfies(mongoose.version, "<7");
52
+ const convertToObject = (value) => {
53
+ if (isMongooseLessThan7) {
54
+ if (value != null && typeof value === "object" && !Array.isArray(value) && value.toObject) {
55
+ return value.toObject();
56
+ }
57
+ if (Array.isArray(value)) {
58
+ return value.map((doc) => convertToObject(doc));
59
+ }
60
+ }
61
+ return value;
62
+ };
63
+
64
+ var __typeError$2 = (msg) => {
65
+ throw TypeError(msg);
66
+ };
67
+ var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
68
+ var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
69
+ var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
70
+ var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
71
+ var _client;
72
+ class RedisCacheEngine {
73
+ constructor(options) {
74
+ __privateAdd$2(this, _client);
75
+ if (!options.keyPrefix) {
76
+ options.keyPrefix = "cache-mongoose:";
77
+ }
78
+ __privateSet$2(this, _client, new IORedis(options));
79
+ }
80
+ async get(key) {
81
+ try {
82
+ const value = await __privateGet$2(this, _client).get(key);
83
+ if (value === null) {
84
+ return void 0;
85
+ }
86
+ return bson.EJSON.parse(value);
87
+ } catch (err) {
88
+ console.error(err);
89
+ return void 0;
90
+ }
91
+ }
92
+ async set(key, value, ttl) {
93
+ try {
94
+ const givenTTL = typeof ttl === "string" ? ms(ttl) : ttl;
95
+ const actualTTL = givenTTL ?? Number.POSITIVE_INFINITY;
96
+ const serializedValue = bson.EJSON.stringify(convertToObject(value));
97
+ await __privateGet$2(this, _client).setex(key, Math.ceil(actualTTL / 1e3), serializedValue);
98
+ } catch (err) {
99
+ console.error(err);
100
+ }
101
+ }
102
+ async del(key) {
103
+ await __privateGet$2(this, _client).del(key);
104
+ }
105
+ async clear() {
106
+ await __privateGet$2(this, _client).flushdb();
107
+ }
108
+ async close() {
109
+ await __privateGet$2(this, _client).quit();
110
+ }
111
+ }
112
+ _client = new WeakMap();
113
+
114
+ var __typeError$1 = (msg) => {
115
+ throw TypeError(msg);
116
+ };
117
+ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
118
+ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
119
+ var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
120
+ var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
121
+ var _engine, _defaultTTL, _debug, _engines;
122
+ class Cache {
123
+ constructor(cacheOptions) {
124
+ __privateAdd$1(this, _engine);
125
+ __privateAdd$1(this, _defaultTTL);
126
+ __privateAdd$1(this, _debug);
127
+ __privateAdd$1(this, _engines, ["memory", "redis"]);
128
+ if (!__privateGet$1(this, _engines).includes(cacheOptions.engine)) {
129
+ throw new Error(`Invalid engine name: ${cacheOptions.engine}`);
130
+ }
131
+ if (cacheOptions.engine === "redis" && !cacheOptions.engineOptions) {
132
+ throw new Error(`Engine options are required for ${cacheOptions.engine} engine`);
133
+ }
134
+ if (!cacheOptions.defaultTTL) {
135
+ cacheOptions.defaultTTL = "1 minute";
136
+ }
137
+ __privateSet$1(this, _defaultTTL, typeof cacheOptions.defaultTTL === "string" ? ms(cacheOptions.defaultTTL) : cacheOptions.defaultTTL);
138
+ if (cacheOptions.engine === "redis" && cacheOptions.engineOptions) {
139
+ __privateSet$1(this, _engine, new RedisCacheEngine(cacheOptions.engineOptions));
140
+ }
141
+ if (cacheOptions.engine === "memory") {
142
+ __privateSet$1(this, _engine, new MemoryCacheEngine());
143
+ }
144
+ __privateSet$1(this, _debug, cacheOptions.debug === true);
145
+ }
146
+ async get(key) {
147
+ const cacheEntry = await __privateGet$1(this, _engine).get(key);
148
+ if (__privateGet$1(this, _debug)) {
149
+ const cacheHit = cacheEntry != null ? "HIT" : "MISS";
150
+ console.log(`[ts-cache-mongoose] GET '${key}' - ${cacheHit}`);
151
+ }
152
+ return cacheEntry;
153
+ }
154
+ async set(key, value, ttl) {
155
+ const givenTTL = typeof ttl === "string" ? ms(ttl) : ttl;
156
+ const actualTTL = givenTTL ?? __privateGet$1(this, _defaultTTL);
157
+ await __privateGet$1(this, _engine).set(key, value, actualTTL);
158
+ if (__privateGet$1(this, _debug)) {
159
+ console.log(`[ts-cache-mongoose] SET '${key}' - ttl: ${actualTTL.toFixed(0)} ms`);
160
+ }
161
+ }
162
+ async del(key) {
163
+ await __privateGet$1(this, _engine).del(key);
164
+ if (__privateGet$1(this, _debug)) {
165
+ console.log(`[ts-cache-mongoose] DEL '${key}'`);
166
+ }
167
+ }
168
+ async clear() {
169
+ await __privateGet$1(this, _engine).clear();
170
+ if (__privateGet$1(this, _debug)) {
171
+ console.log("[ts-cache-mongoose] CLEAR");
172
+ }
173
+ }
174
+ async close() {
175
+ return __privateGet$1(this, _engine).close();
176
+ }
177
+ }
178
+ _engine = new WeakMap();
179
+ _defaultTTL = new WeakMap();
180
+ _debug = new WeakMap();
181
+ _engines = new WeakMap();
182
+
183
+ function getKey(data) {
184
+ const sortedObj = sortKeys(data, { deep: true });
185
+ const sortedStr = JSON.stringify(sortedObj, (_, val) => {
186
+ return val instanceof RegExp ? String(val) : val;
187
+ });
188
+ return node_crypto.createHash("sha1").update(sortedStr).digest("hex");
189
+ }
190
+
191
+ function extendAggregate(mongoose, cache) {
192
+ const mongooseExec = mongoose.Aggregate.prototype.exec;
193
+ mongoose.Aggregate.prototype.getCacheKey = function() {
194
+ if (this._key != null) return this._key;
195
+ return getKey({
196
+ pipeline: this.pipeline()
197
+ });
198
+ };
199
+ mongoose.Aggregate.prototype.getCacheTTL = function() {
200
+ return this._ttl;
201
+ };
202
+ mongoose.Aggregate.prototype.cache = function(ttl, customKey) {
203
+ this._ttl = ttl ?? null;
204
+ this._key = customKey ?? null;
205
+ return this;
206
+ };
207
+ mongoose.Aggregate.prototype.exec = async function(...args) {
208
+ if (!Object.prototype.hasOwnProperty.call(this, "_ttl")) {
209
+ return mongooseExec.apply(this, args);
210
+ }
211
+ const key = this.getCacheKey();
212
+ const ttl = this.getCacheTTL();
213
+ const resultCache = await cache.get(key).catch((err) => {
214
+ console.error(err);
215
+ });
216
+ if (resultCache) {
217
+ return resultCache;
218
+ }
219
+ const result = await mongooseExec.call(this);
220
+ await cache.set(key, result, ttl).catch((err) => {
221
+ console.error(err);
222
+ });
223
+ return result;
224
+ };
225
+ }
226
+
227
+ function extendQuery(mongoose, cache) {
228
+ const mongooseExec = mongoose.Query.prototype.exec;
229
+ mongoose.Query.prototype.getCacheKey = function() {
230
+ if (this._key != null) return this._key;
231
+ const filter = this.getFilter();
232
+ const update = this.getUpdate();
233
+ const options = this.getOptions();
234
+ const mongooseOptions = this.mongooseOptions();
235
+ return getKey({
236
+ model: this.model.modelName,
237
+ op: this.op,
238
+ filter,
239
+ update,
240
+ options,
241
+ mongooseOptions,
242
+ _path: this._path,
243
+ _fields: this._fields,
244
+ _distinct: this._distinct,
245
+ _conditions: this._conditions
246
+ });
247
+ };
248
+ mongoose.Query.prototype.getCacheTTL = function() {
249
+ return this._ttl;
250
+ };
251
+ mongoose.Query.prototype.cache = function(ttl, customKey) {
252
+ this._ttl = ttl ?? null;
253
+ this._key = customKey ?? null;
254
+ return this;
255
+ };
256
+ mongoose.Query.prototype.exec = async function(...args) {
257
+ if (!Object.prototype.hasOwnProperty.call(this, "_ttl")) {
258
+ return mongooseExec.apply(this, args);
259
+ }
260
+ const key = this.getCacheKey();
261
+ const ttl = this.getCacheTTL();
262
+ const mongooseOptions = this.mongooseOptions();
263
+ const isCount = this.op?.includes("count") ?? false;
264
+ const isDistinct = this.op === "distinct";
265
+ const model = this.model.modelName;
266
+ const resultCache = await cache.get(key).catch((err) => {
267
+ console.error(err);
268
+ });
269
+ if (resultCache) {
270
+ if (isCount || isDistinct || mongooseOptions.lean) {
271
+ return resultCache;
272
+ }
273
+ const modelConstructor = mongoose.model(model);
274
+ if (Array.isArray(resultCache)) {
275
+ return resultCache.map((item) => {
276
+ return modelConstructor.hydrate(item);
277
+ });
278
+ }
279
+ return modelConstructor.hydrate(resultCache);
280
+ }
281
+ const result = await mongooseExec.call(this);
282
+ await cache.set(key, result, ttl).catch((err) => {
283
+ console.error(err);
284
+ });
285
+ return result;
286
+ };
287
+ }
288
+
289
+ var __typeError = (msg) => {
290
+ throw TypeError(msg);
291
+ };
292
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
293
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
294
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
295
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
296
+ var _instance;
297
+ const _CacheMongoose = class _CacheMongoose {
298
+ constructor() {
299
+ }
300
+ static init(mongoose, cacheOptions) {
301
+ if (!__privateGet(_CacheMongoose, _instance)) {
302
+ __privateSet(_CacheMongoose, _instance, new _CacheMongoose());
303
+ __privateGet(_CacheMongoose, _instance).cache = new Cache(cacheOptions);
304
+ const cache = __privateGet(_CacheMongoose, _instance).cache;
305
+ extendQuery(mongoose, cache);
306
+ extendAggregate(mongoose, cache);
307
+ }
308
+ return __privateGet(_CacheMongoose, _instance);
309
+ }
310
+ async clear(customKey) {
311
+ if (customKey != null) {
312
+ await this.cache.del(customKey);
313
+ } else {
314
+ await this.cache.clear();
315
+ }
316
+ }
317
+ async close() {
318
+ await this.cache.close();
319
+ }
320
+ };
321
+ _instance = new WeakMap();
322
+ __privateAdd(_CacheMongoose, _instance);
323
+ let CacheMongoose = _CacheMongoose;
324
+
325
+ module.exports = CacheMongoose;
@@ -1,5 +1,23 @@
1
- import type { Mongoose } from 'mongoose';
2
- import type { CacheOptions, CacheTTL } from './types';
1
+ import { Mongoose } from 'mongoose';
2
+ import { RedisOptions } from 'ioredis';
3
+ import { StringValue } from 'ms';
4
+
5
+ type CacheTTL = number | StringValue;
6
+ type CacheData = Record<string, unknown> | Record<string, unknown>[] | unknown[] | number | undefined;
7
+ type CacheOptions = {
8
+ engine: 'memory' | 'redis';
9
+ engineOptions?: RedisOptions;
10
+ defaultTTL?: CacheTTL;
11
+ debug?: boolean;
12
+ };
13
+ interface CacheEngine {
14
+ get: (key: string) => Promise<CacheData> | CacheData;
15
+ set: (key: string, value: CacheData, ttl?: CacheTTL) => Promise<void> | void;
16
+ del: (key: string) => Promise<void> | void;
17
+ clear: () => Promise<void> | void;
18
+ close: () => Promise<void> | void;
19
+ }
20
+
3
21
  declare module 'mongoose' {
4
22
  interface Query<ResultType, DocType, THelpers, RawDocType> {
5
23
  cache: (this: Query<ResultType, DocType, THelpers, RawDocType>, ttl?: CacheTTL, customKey?: string) => this;
@@ -29,5 +47,5 @@ declare class CacheMongoose {
29
47
  clear(customKey?: string): Promise<void>;
30
48
  close(): Promise<void>;
31
49
  }
32
- export default CacheMongoose;
33
- //# sourceMappingURL=plugin.d.ts.map
50
+
51
+ export { type CacheData, type CacheEngine, type CacheOptions, type CacheTTL, CacheMongoose as default };
@@ -1,5 +1,23 @@
1
- import type { Mongoose } from 'mongoose';
2
- import type { CacheOptions, CacheTTL } from './types';
1
+ import { Mongoose } from 'mongoose';
2
+ import { RedisOptions } from 'ioredis';
3
+ import { StringValue } from 'ms';
4
+
5
+ type CacheTTL = number | StringValue;
6
+ type CacheData = Record<string, unknown> | Record<string, unknown>[] | unknown[] | number | undefined;
7
+ type CacheOptions = {
8
+ engine: 'memory' | 'redis';
9
+ engineOptions?: RedisOptions;
10
+ defaultTTL?: CacheTTL;
11
+ debug?: boolean;
12
+ };
13
+ interface CacheEngine {
14
+ get: (key: string) => Promise<CacheData> | CacheData;
15
+ set: (key: string, value: CacheData, ttl?: CacheTTL) => Promise<void> | void;
16
+ del: (key: string) => Promise<void> | void;
17
+ clear: () => Promise<void> | void;
18
+ close: () => Promise<void> | void;
19
+ }
20
+
3
21
  declare module 'mongoose' {
4
22
  interface Query<ResultType, DocType, THelpers, RawDocType> {
5
23
  cache: (this: Query<ResultType, DocType, THelpers, RawDocType>, ttl?: CacheTTL, customKey?: string) => this;
@@ -29,5 +47,5 @@ declare class CacheMongoose {
29
47
  clear(customKey?: string): Promise<void>;
30
48
  close(): Promise<void>;
31
49
  }
32
- export default CacheMongoose;
33
- //# sourceMappingURL=plugin.d.ts.map
50
+
51
+ export { type CacheData, type CacheEngine, type CacheOptions, type CacheTTL, CacheMongoose as default };