@nestjs-redisx/cache 1.0.0

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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/dist/cache/api/decorators/cached.decorator.d.ts +152 -0
  4. package/dist/cache/api/decorators/cached.decorator.d.ts.map +1 -0
  5. package/dist/cache/api/decorators/invalidate-tags.decorator.d.ts +44 -0
  6. package/dist/cache/api/decorators/invalidate-tags.decorator.d.ts.map +1 -0
  7. package/dist/cache/application/ports/cache-service.port.d.ts +120 -0
  8. package/dist/cache/application/ports/cache-service.port.d.ts.map +1 -0
  9. package/dist/cache/application/ports/l1-cache-store.port.d.ts +56 -0
  10. package/dist/cache/application/ports/l1-cache-store.port.d.ts.map +1 -0
  11. package/dist/cache/application/ports/l2-cache-store.port.d.ts +98 -0
  12. package/dist/cache/application/ports/l2-cache-store.port.d.ts.map +1 -0
  13. package/dist/cache/application/services/cache-decorator-initializer.service.d.ts +25 -0
  14. package/dist/cache/application/services/cache-decorator-initializer.service.d.ts.map +1 -0
  15. package/dist/cache/application/services/cache.service.d.ts +106 -0
  16. package/dist/cache/application/services/cache.service.d.ts.map +1 -0
  17. package/dist/cache/application/services/warmup.service.d.ts +25 -0
  18. package/dist/cache/application/services/warmup.service.d.ts.map +1 -0
  19. package/dist/cache/domain/services/serializer.service.d.ts +29 -0
  20. package/dist/cache/domain/services/serializer.service.d.ts.map +1 -0
  21. package/dist/cache/domain/value-objects/cache-entry.vo.d.ts +69 -0
  22. package/dist/cache/domain/value-objects/cache-entry.vo.d.ts.map +1 -0
  23. package/dist/cache/domain/value-objects/cache-key.vo.d.ts +45 -0
  24. package/dist/cache/domain/value-objects/cache-key.vo.d.ts.map +1 -0
  25. package/dist/cache/domain/value-objects/tag.vo.d.ts +36 -0
  26. package/dist/cache/domain/value-objects/tag.vo.d.ts.map +1 -0
  27. package/dist/cache/domain/value-objects/tags.vo.d.ts +57 -0
  28. package/dist/cache/domain/value-objects/tags.vo.d.ts.map +1 -0
  29. package/dist/cache/domain/value-objects/ttl.vo.d.ts +58 -0
  30. package/dist/cache/domain/value-objects/ttl.vo.d.ts.map +1 -0
  31. package/dist/cache/infrastructure/adapters/l1-memory-store.adapter.d.ts +36 -0
  32. package/dist/cache/infrastructure/adapters/l1-memory-store.adapter.d.ts.map +1 -0
  33. package/dist/cache/infrastructure/adapters/l2-redis-store.adapter.d.ts +41 -0
  34. package/dist/cache/infrastructure/adapters/l2-redis-store.adapter.d.ts.map +1 -0
  35. package/dist/cache.plugin.d.ts +17 -0
  36. package/dist/cache.plugin.d.ts.map +1 -0
  37. package/dist/cache.service.d.ts +234 -0
  38. package/dist/cache.service.d.ts.map +1 -0
  39. package/dist/decorators/cache-evict.decorator.d.ts +97 -0
  40. package/dist/decorators/cache-evict.decorator.d.ts.map +1 -0
  41. package/dist/decorators/cache-put.decorator.d.ts +95 -0
  42. package/dist/decorators/cache-put.decorator.d.ts.map +1 -0
  43. package/dist/decorators/cache.interceptor.d.ts +63 -0
  44. package/dist/decorators/cache.interceptor.d.ts.map +1 -0
  45. package/dist/decorators/cacheable.decorator.d.ts +88 -0
  46. package/dist/decorators/cacheable.decorator.d.ts.map +1 -0
  47. package/dist/decorators/key-generator.util.d.ts +69 -0
  48. package/dist/decorators/key-generator.util.d.ts.map +1 -0
  49. package/dist/index.d.ts +39 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +4199 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/index.mjs +4152 -0
  54. package/dist/index.mjs.map +1 -0
  55. package/dist/invalidation/application/ports/event-invalidation.port.d.ts +28 -0
  56. package/dist/invalidation/application/ports/event-invalidation.port.d.ts.map +1 -0
  57. package/dist/invalidation/application/ports/invalidation-registry.port.d.ts +36 -0
  58. package/dist/invalidation/application/ports/invalidation-registry.port.d.ts.map +1 -0
  59. package/dist/invalidation/application/services/event-invalidation.service.d.ts +30 -0
  60. package/dist/invalidation/application/services/event-invalidation.service.d.ts.map +1 -0
  61. package/dist/invalidation/application/services/invalidation-registry.service.d.ts +17 -0
  62. package/dist/invalidation/application/services/invalidation-registry.service.d.ts.map +1 -0
  63. package/dist/invalidation/domain/entities/invalidation-rule.entity.d.ts +60 -0
  64. package/dist/invalidation/domain/entities/invalidation-rule.entity.d.ts.map +1 -0
  65. package/dist/invalidation/domain/value-objects/event-pattern.vo.d.ts +27 -0
  66. package/dist/invalidation/domain/value-objects/event-pattern.vo.d.ts.map +1 -0
  67. package/dist/invalidation/domain/value-objects/tag-template.vo.d.ts +34 -0
  68. package/dist/invalidation/domain/value-objects/tag-template.vo.d.ts.map +1 -0
  69. package/dist/invalidation/infrastructure/adapters/amqp-event-source.adapter.d.ts +51 -0
  70. package/dist/invalidation/infrastructure/adapters/amqp-event-source.adapter.d.ts.map +1 -0
  71. package/dist/invalidation/infrastructure/decorators/invalidate-on.decorator.d.ts +69 -0
  72. package/dist/invalidation/infrastructure/decorators/invalidate-on.decorator.d.ts.map +1 -0
  73. package/dist/key-builder.d.ts +199 -0
  74. package/dist/key-builder.d.ts.map +1 -0
  75. package/dist/serializers/index.d.ts +19 -0
  76. package/dist/serializers/index.d.ts.map +1 -0
  77. package/dist/serializers/json.serializer.d.ts +51 -0
  78. package/dist/serializers/json.serializer.d.ts.map +1 -0
  79. package/dist/serializers/msgpack.serializer.d.ts +67 -0
  80. package/dist/serializers/msgpack.serializer.d.ts.map +1 -0
  81. package/dist/serializers/serializer.interface.d.ts +36 -0
  82. package/dist/serializers/serializer.interface.d.ts.map +1 -0
  83. package/dist/shared/constants/index.d.ts +73 -0
  84. package/dist/shared/constants/index.d.ts.map +1 -0
  85. package/dist/shared/errors/index.d.ts +46 -0
  86. package/dist/shared/errors/index.d.ts.map +1 -0
  87. package/dist/shared/types/context-provider.interface.d.ts +58 -0
  88. package/dist/shared/types/context-provider.interface.d.ts.map +1 -0
  89. package/dist/shared/types/index.d.ts +259 -0
  90. package/dist/shared/types/index.d.ts.map +1 -0
  91. package/dist/stampede/application/ports/stampede-protection.port.d.ts +33 -0
  92. package/dist/stampede/application/ports/stampede-protection.port.d.ts.map +1 -0
  93. package/dist/stampede/infrastructure/stampede-protection.service.d.ts +30 -0
  94. package/dist/stampede/infrastructure/stampede-protection.service.d.ts.map +1 -0
  95. package/dist/strategies/eviction-strategy.interface.d.ts +39 -0
  96. package/dist/strategies/eviction-strategy.interface.d.ts.map +1 -0
  97. package/dist/strategies/fifo.strategy.d.ts +86 -0
  98. package/dist/strategies/fifo.strategy.d.ts.map +1 -0
  99. package/dist/strategies/index.d.ts +19 -0
  100. package/dist/strategies/index.d.ts.map +1 -0
  101. package/dist/strategies/lfu.strategy.d.ts +87 -0
  102. package/dist/strategies/lfu.strategy.d.ts.map +1 -0
  103. package/dist/strategies/lru.strategy.d.ts +78 -0
  104. package/dist/strategies/lru.strategy.d.ts.map +1 -0
  105. package/dist/swr/application/ports/swr-manager.port.d.ts +83 -0
  106. package/dist/swr/application/ports/swr-manager.port.d.ts.map +1 -0
  107. package/dist/swr/infrastructure/swr-manager.service.d.ts +30 -0
  108. package/dist/swr/infrastructure/swr-manager.service.d.ts.map +1 -0
  109. package/dist/tags/application/ports/tag-index.port.d.ts +55 -0
  110. package/dist/tags/application/ports/tag-index.port.d.ts.map +1 -0
  111. package/dist/tags/infrastructure/repositories/tag-index.repository.d.ts +37 -0
  112. package/dist/tags/infrastructure/repositories/tag-index.repository.d.ts.map +1 -0
  113. package/dist/tags/infrastructure/scripts/lua-scripts.d.ts +25 -0
  114. package/dist/tags/infrastructure/scripts/lua-scripts.d.ts.map +1 -0
  115. package/dist/tags/infrastructure/services/lua-script-loader.service.d.ts +44 -0
  116. package/dist/tags/infrastructure/services/lua-script-loader.service.d.ts.map +1 -0
  117. package/package.json +79 -0
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Main cache service.
3
+ * Simplified API wrapper over the internal cache implementation.
4
+ */
5
+ import { ICacheService as IInternalCacheService } from './cache/application/ports/cache-service.port';
6
+ import { CacheSetOptions, CacheGetOrSetOptions, CacheStats } from './shared/types';
7
+ export declare class CacheService {
8
+ private readonly internalCache;
9
+ constructor(internalCache: IInternalCacheService);
10
+ /**
11
+ * Gets value from cache.
12
+ *
13
+ * @param key - Cache key
14
+ * @returns Cached value or null if not found
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const user = await cacheService.get<User>('user:123');
19
+ * ```
20
+ */
21
+ get<T>(key: string): Promise<T | null>;
22
+ /**
23
+ * Sets value in cache with optional TTL and tags.
24
+ *
25
+ * @param key - Cache key
26
+ * @param value - Value to cache
27
+ * @param options - Cache options (ttl, tags, strategy)
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * await cacheService.set('user:123', user, {
32
+ * ttl: 3600,
33
+ * tags: ['users', 'user:123']
34
+ * });
35
+ * ```
36
+ */
37
+ set<T>(key: string, value: T, options?: CacheSetOptions): Promise<void>;
38
+ /**
39
+ * Deletes key from cache.
40
+ *
41
+ * @param key - Cache key
42
+ * @returns True if key was deleted, false if not found
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const deleted = await cacheService.del('user:123');
47
+ * ```
48
+ */
49
+ del(key: string): Promise<boolean>;
50
+ /**
51
+ * Gets multiple values from cache.
52
+ *
53
+ * @param keys - Array of cache keys
54
+ * @returns Array of values (null for missing keys)
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const users = await cacheService.getMany<User>(['user:1', 'user:2', 'user:3']);
59
+ * ```
60
+ */
61
+ getMany<T>(keys: string[]): Promise<Array<T | null>>;
62
+ /**
63
+ * Sets multiple values in cache.
64
+ *
65
+ * @param entries - Array of key-value-ttl tuples
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * await cacheService.setMany([
70
+ * { key: 'user:1', value: user1, ttl: 3600 },
71
+ * { key: 'user:2', value: user2, ttl: 3600 }
72
+ * ]);
73
+ * ```
74
+ */
75
+ setMany<T>(entries: Array<{
76
+ key: string;
77
+ value: T;
78
+ ttl?: number;
79
+ }>): Promise<void>;
80
+ /**
81
+ * Gets value from cache or loads it using the provided loader function.
82
+ * Implements cache-aside pattern with anti-stampede protection.
83
+ *
84
+ * @param key - Cache key
85
+ * @param loader - Function to load value if not cached
86
+ * @param options - Cache options
87
+ * @returns Cached or loaded value
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const user = await cacheService.getOrSet(
92
+ * 'user:123',
93
+ * async () => {
94
+ * return await userRepository.findById('123');
95
+ * },
96
+ * { ttl: 3600, tags: ['users'] }
97
+ * );
98
+ * ```
99
+ */
100
+ getOrSet<T>(key: string, loader: () => Promise<T>, options?: CacheGetOrSetOptions): Promise<T>;
101
+ /**
102
+ * Wraps a function with caching logic.
103
+ * Helper for creating cached functions.
104
+ *
105
+ * @param fn - Function to wrap
106
+ * @param options - Cache options or key builder function
107
+ * @returns Wrapped function with caching
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const getCachedUser = cacheService.wrap(
112
+ * async (id: string) => userRepository.findById(id),
113
+ * {
114
+ * key: (id: string) => `user:${id}`,
115
+ * ttl: 3600,
116
+ * tags: (id: string) => [`user:${id}`, 'users']
117
+ * }
118
+ * );
119
+ *
120
+ * const user = await getCachedUser('123');
121
+ * ```
122
+ */
123
+ wrap<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>, options: {
124
+ key: (...args: TArgs) => string;
125
+ ttl?: number;
126
+ tags?: string[] | ((...args: TArgs) => string[]);
127
+ }): (...args: TArgs) => Promise<TReturn>;
128
+ /**
129
+ * Deletes multiple keys from cache.
130
+ *
131
+ * @param keys - Array of cache keys
132
+ * @returns Number of keys deleted
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const count = await cacheService.deleteMany(['user:1', 'user:2', 'user:3']);
137
+ * console.log(`Deleted ${count} keys`);
138
+ * ```
139
+ */
140
+ deleteMany(keys: string[]): Promise<number>;
141
+ /**
142
+ * Gets all cache keys associated with a tag.
143
+ *
144
+ * @param tag - Tag name
145
+ * @returns Array of cache keys
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const keys = await cacheService.getKeysByTag('users');
150
+ * console.log(`Found ${keys.length} cached user keys`);
151
+ * ```
152
+ */
153
+ getKeysByTag(tag: string): Promise<string[]>;
154
+ /**
155
+ * Invalidates cache by tag.
156
+ *
157
+ * @param tag - Tag to invalidate
158
+ * @returns Number of keys invalidated
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // Invalidate all user caches
163
+ * const count = await cacheService.invalidate('users');
164
+ * console.log(`Invalidated ${count} keys`);
165
+ * ```
166
+ */
167
+ invalidate(tag: string): Promise<number>;
168
+ /**
169
+ * Invalidates multiple tags.
170
+ *
171
+ * @param tags - Array of tags to invalidate
172
+ * @returns Total number of keys invalidated
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const count = await cacheService.invalidate(['users', 'products']);
177
+ * ```
178
+ */
179
+ invalidateTags(tags: string[]): Promise<number>;
180
+ /**
181
+ * Invalidates cache keys matching a pattern.
182
+ * Uses Redis SCAN for safe iteration.
183
+ *
184
+ * @param pattern - Redis pattern (supports * and ?)
185
+ * @returns Number of keys deleted
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * // Delete all user-related caches
190
+ * await cacheService.invalidateByPattern('user:*');
191
+ *
192
+ * // Delete specific locale caches
193
+ * await cacheService.invalidateByPattern('*:en_US');
194
+ * ```
195
+ */
196
+ invalidateByPattern(pattern: string): Promise<number>;
197
+ /**
198
+ * Checks if key exists in cache.
199
+ *
200
+ * @param key - Cache key
201
+ * @returns True if key exists
202
+ */
203
+ has(key: string): Promise<boolean>;
204
+ /**
205
+ * Gets TTL for a cached key.
206
+ *
207
+ * @param key - Cache key
208
+ * @returns TTL in seconds, -1 if no TTL, -2 if key doesn't exist
209
+ */
210
+ ttl(key: string): Promise<number>;
211
+ /**
212
+ * Clears all cache entries.
213
+ * Use with caution in production.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * await cacheService.clear();
218
+ * ```
219
+ */
220
+ clear(): Promise<void>;
221
+ /**
222
+ * Gets cache statistics.
223
+ *
224
+ * @returns Cache stats (hits, misses, size)
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const stats = await cacheService.getStats();
229
+ * console.log(`L1 Hit Rate: ${stats.l1.hits / (stats.l1.hits + stats.l1.misses) * 100}%`);
230
+ * ```
231
+ */
232
+ getStats(): Promise<CacheStats>;
233
+ }
234
+ //# sourceMappingURL=cache.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.service.d.ts","sourceRoot":"","sources":["../src/cache.service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAEtG,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEnF,qBACa,YAAY;IAGrB,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAAb,aAAa,EAAE,qBAAqB;IAGvD;;;;;;;;;;OAUG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAI5C;;;;;;;;;;;;;;OAcG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7E;;;;;;;;;;OAUG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxC;;;;;;;;;;OAUG;IACG,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAI1D;;;;;;;;;;;;OAYG;IACG,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxF;;;;;;;;;;;;;;;;;;;OAmBG;IACG,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpG;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,IAAI,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EACnC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,EACxC,OAAO,EAAE;QACP,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC;QAChC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM,EAAE,CAAC,CAAC;KAClD,GACA,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC;IAYvC;;;;;;;;;;;OAWG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjD;;;;;;;;;;;OAWG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIlD;;;;;;;;;;;;OAYG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9C;;;;;;;;;;OAUG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrD;;;;;;;;;;;;;;;OAeG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3D;;;;;OAKG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxC;;;;;OAKG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvC;;;;;;;;OAQG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;;;;;;;;OAUG;IACG,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;CAGtC"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @CacheEvict decorator for cache invalidation.
3
+ *
4
+ * Evicts (removes) cache entries after method execution.
5
+ * Supports multiple keys, tags, and patterns.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * class UserService {
10
+ * @CacheEvict({
11
+ * keys: ['user:{id}'],
12
+ * tags: ['users']
13
+ * })
14
+ * async updateUser(id: string, data: UpdateUserDto) {
15
+ * return this.repository.update(id, data);
16
+ * }
17
+ *
18
+ * @CacheEvict({
19
+ * keys: ['user:{userId}:posts:*'],
20
+ * beforeInvocation: false
21
+ * })
22
+ * async deleteUserPosts(userId: string) {
23
+ * return this.repository.deletePosts(userId);
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ /**
29
+ * Options for @CacheEvict decorator.
30
+ */
31
+ export interface ICacheEvictOptions {
32
+ /**
33
+ * Cache keys or key templates to evict.
34
+ * Supports parameter interpolation and wildcards.
35
+ *
36
+ * @example ['user:{id}']
37
+ * @example ['user:{userId}:posts:*']
38
+ */
39
+ keys?: string[];
40
+ /**
41
+ * Tags to invalidate.
42
+ * All keys with these tags will be evicted.
43
+ */
44
+ tags?: string[];
45
+ /**
46
+ * Whether to evict all cache entries.
47
+ * Use with caution - this clears the entire cache.
48
+ *
49
+ * @default false
50
+ */
51
+ allEntries?: boolean;
52
+ /**
53
+ * Whether to evict cache before method invocation.
54
+ * - true: evict before execution
55
+ * - false: evict after execution (default)
56
+ *
57
+ * @default false
58
+ */
59
+ beforeInvocation?: boolean;
60
+ /**
61
+ * Condition to determine if cache should be evicted.
62
+ * Return false to skip eviction for specific cases.
63
+ */
64
+ condition?: (...args: unknown[]) => boolean;
65
+ /**
66
+ * Custom key generator function.
67
+ * If provided, overrides template-based key generation.
68
+ */
69
+ keyGenerator?: (...args: unknown[]) => string[];
70
+ /**
71
+ * Namespace prefix for the keys.
72
+ * @default ''
73
+ */
74
+ namespace?: string;
75
+ }
76
+ /**
77
+ * Metadata key for @CacheEvict decorator.
78
+ */
79
+ export declare const CACHE_EVICT_METADATA_KEY = "cache:evict";
80
+ /**
81
+ * @CacheEvict decorator.
82
+ *
83
+ * Automatically evicts cache entries after (or before) method execution.
84
+ * Supports multiple keys, tags, and pattern matching.
85
+ *
86
+ * @param options - Eviction options
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * @CacheEvict({ keys: ['user:{id}'], tags: ['users'] })
91
+ * async updateUser(id: string, data: UpdateUserDto) {
92
+ * return await this.repository.update(id, data);
93
+ * }
94
+ * ```
95
+ */
96
+ export declare function CacheEvict(options?: ICacheEvictOptions): MethodDecorator;
97
+ //# sourceMappingURL=cache-evict.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-evict.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/cache-evict.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAE5C;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;IAEhD;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,gBAAgB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,kBAAuB,GAAG,eAAe,CAE5E"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @CachePut decorator for cache updates.
3
+ *
4
+ * Always executes the method and updates the cache with the result.
5
+ * Unlike @Cacheable, it doesn't check the cache before execution.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * class UserService {
10
+ * @CachePut({
11
+ * key: 'user:{id}',
12
+ * tags: ['users']
13
+ * })
14
+ * async updateUser(id: string, data: UpdateUserDto) {
15
+ * const updated = await this.repository.update(id, data);
16
+ * return updated; // This result will be cached
17
+ * }
18
+ *
19
+ * @CachePut({
20
+ * key: 'user:{user.id}',
21
+ * ttl: 1800
22
+ * })
23
+ * async createUser(user: CreateUserDto) {
24
+ * const created = await this.repository.create(user);
25
+ * return created; // This result will be cached
26
+ * }
27
+ * }
28
+ * ```
29
+ */
30
+ /**
31
+ * Options for @CachePut decorator.
32
+ */
33
+ export interface ICachePutOptions {
34
+ /**
35
+ * Cache key template. Supports parameter interpolation.
36
+ * Use {paramName} to interpolate method parameters.
37
+ * Supports nested properties: {user.id}
38
+ *
39
+ * @example 'user:{id}'
40
+ * @example 'user:{user.id}'
41
+ */
42
+ key: string;
43
+ /**
44
+ * TTL in seconds.
45
+ * @default 3600
46
+ */
47
+ ttl?: number;
48
+ /**
49
+ * Tags for invalidation.
50
+ * Can be static array or function that returns array.
51
+ */
52
+ tags?: string[] | ((...args: unknown[]) => string[]);
53
+ /**
54
+ * Condition to determine if result should be cached.
55
+ * Return false to skip caching for specific cases.
56
+ */
57
+ condition?: (...args: unknown[]) => boolean;
58
+ /**
59
+ * Custom key generator function.
60
+ * If provided, overrides template-based key generation.
61
+ */
62
+ keyGenerator?: (...args: unknown[]) => string;
63
+ /**
64
+ * Namespace prefix for the key.
65
+ * @default ''
66
+ */
67
+ namespace?: string;
68
+ /**
69
+ * Whether to cache null/undefined results.
70
+ * @default false
71
+ */
72
+ cacheNullValues?: boolean;
73
+ }
74
+ /**
75
+ * Metadata key for @CachePut decorator.
76
+ */
77
+ export declare const CACHE_PUT_METADATA_KEY = "cache:put";
78
+ /**
79
+ * @CachePut decorator.
80
+ *
81
+ * Always executes the method and caches the result.
82
+ * Useful for update operations where you want to refresh the cache.
83
+ *
84
+ * @param options - Cache put options
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * @CachePut({ key: 'user:{id}', ttl: 3600 })
89
+ * async updateUser(id: string, data: UpdateUserDto) {
90
+ * return await this.repository.update(id, data);
91
+ * }
92
+ * ```
93
+ */
94
+ export declare function CachePut(options: ICachePutOptions): MethodDecorator;
95
+ //# sourceMappingURL=cache-put.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-put.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/cache-put.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;IAErD;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAE5C;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC;IAE9C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAEnE"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Cache interceptor for handling @Cacheable, @CachePut, and @CacheEvict decorators.
3
+ */
4
+ import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
5
+ import { Reflector } from '@nestjs/core';
6
+ import { Observable } from 'rxjs';
7
+ import { CacheService } from '../cache.service';
8
+ /**
9
+ * Interceptor for cache decorators.
10
+ *
11
+ * Handles:
12
+ * - @Cacheable: Returns cached value or executes and caches result
13
+ * - @CachePut: Always executes and caches result
14
+ * - @CacheEvict: Evicts cache entries before or after execution
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * @Controller('users')
19
+ * @UseInterceptors(CacheInterceptor)
20
+ * export class UserController {
21
+ * @Get(':id')
22
+ * @Cacheable({ key: 'user:{id}', ttl: 3600 })
23
+ * getUser(@Param('id') id: string) {
24
+ * return this.userService.findOne(id);
25
+ * }
26
+ *
27
+ * @Put(':id')
28
+ * @CachePut({ key: 'user:{id}' })
29
+ * updateUser(@Param('id') id: string, @Body() data: UpdateUserDto) {
30
+ * return this.userService.update(id, data);
31
+ * }
32
+ *
33
+ * @Delete(':id')
34
+ * @CacheEvict({ keys: ['user:{id}'] })
35
+ * deleteUser(@Param('id') id: string) {
36
+ * return this.userService.delete(id);
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ export declare class CacheInterceptor implements NestInterceptor {
42
+ private readonly cacheService;
43
+ private readonly reflector;
44
+ private readonly logger;
45
+ constructor(cacheService: CacheService, reflector: Reflector);
46
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
47
+ /**
48
+ * Handles @Cacheable decorator.
49
+ * Returns cached value or executes method and caches result.
50
+ */
51
+ private handleCacheable;
52
+ /**
53
+ * Handles @CachePut decorator.
54
+ * Always executes method and caches the result.
55
+ */
56
+ private handleCachePut;
57
+ /**
58
+ * Handles @CacheEvict decorator.
59
+ * Evicts cache entries before or after method execution.
60
+ */
61
+ private handleCacheEvict;
62
+ }
63
+ //# sourceMappingURL=cache.interceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.interceptor.d.ts","sourceRoot":"","sources":["../../src/decorators/cache.interceptor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAc,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAU,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAY,MAAM,MAAM,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBACa,gBAAiB,YAAW,eAAe;IAIpD,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJ5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;gBAGzC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS;IAGvC,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IAiC5E;;;OAGG;IACH,OAAO,CAAC,eAAe;IAqDvB;;;OAGG;IACH,OAAO,CAAC,cAAc;IA+CtB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;CA8DzB"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @Cacheable decorator for automatic method result caching.
3
+ *
4
+ * Caches method results and returns cached value on subsequent calls.
5
+ * Supports key templates with parameter interpolation.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * class UserService {
10
+ * @Cacheable({
11
+ * key: 'user:{id}',
12
+ * ttl: 3600,
13
+ * tags: ['users']
14
+ * })
15
+ * async getUser(id: string) {
16
+ * return this.repository.findById(id);
17
+ * }
18
+ *
19
+ * @Cacheable({
20
+ * key: 'user:{userId}:posts:{postId}',
21
+ * ttl: 1800
22
+ * })
23
+ * async getUserPost(userId: string, postId: string) {
24
+ * return this.repository.findPost(userId, postId);
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ /**
30
+ * Options for @Cacheable decorator.
31
+ */
32
+ export interface ICacheableOptions {
33
+ /**
34
+ * Cache key template. Supports parameter interpolation.
35
+ * Use {paramName} to interpolate method parameters.
36
+ *
37
+ * @example 'user:{id}'
38
+ * @example 'post:{userId}:{postId}'
39
+ */
40
+ key: string;
41
+ /**
42
+ * TTL in seconds.
43
+ * @default 3600
44
+ */
45
+ ttl?: number;
46
+ /**
47
+ * Tags for invalidation.
48
+ * Can be static array or function that returns array.
49
+ */
50
+ tags?: string[] | ((...args: unknown[]) => string[]);
51
+ /**
52
+ * Condition to determine if result should be cached.
53
+ * Return false to skip caching for specific cases.
54
+ */
55
+ condition?: (...args: unknown[]) => boolean;
56
+ /**
57
+ * Custom key generator function.
58
+ * If provided, overrides template-based key generation.
59
+ */
60
+ keyGenerator?: (...args: unknown[]) => string;
61
+ /**
62
+ * Namespace prefix for the key.
63
+ * @default ''
64
+ */
65
+ namespace?: string;
66
+ }
67
+ /**
68
+ * Metadata key for @Cacheable decorator.
69
+ */
70
+ export declare const CACHEABLE_METADATA_KEY = "cache:cacheable";
71
+ /**
72
+ * @Cacheable decorator.
73
+ *
74
+ * Automatically caches method results using the configured key template.
75
+ * Supports parameter interpolation in key templates.
76
+ *
77
+ * @param options - Caching options
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * @Cacheable({ key: 'user:{id}', ttl: 3600 })
82
+ * async getUser(id: string) {
83
+ * return await this.repository.findById(id);
84
+ * }
85
+ * ```
86
+ */
87
+ export declare function Cacheable(options: ICacheableOptions): MethodDecorator;
88
+ //# sourceMappingURL=cacheable.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheable.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/cacheable.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;IAErD;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAE5C;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC;IAE9C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,oBAAoB,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe,CAErE"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Utility functions for cache key generation from templates.
3
+ */
4
+ /**
5
+ * Extracts parameter names from method signature.
6
+ *
7
+ * @param method - Method to extract parameters from
8
+ * @returns Array of parameter names
9
+ */
10
+ export declare function getParameterNames(method: Function): string[];
11
+ /**
12
+ * Gets nested property value from object.
13
+ *
14
+ * @param obj - Object to get value from
15
+ * @param path - Property path (e.g., 'user.id')
16
+ * @returns Property value or undefined
17
+ *
18
+ * @example
19
+ * getNestedValue({ user: { id: '123' } }, 'user.id') // '123'
20
+ */
21
+ export declare function getNestedValue(obj: unknown, path: string): unknown;
22
+ /**
23
+ * Generates cache key from template and method arguments.
24
+ *
25
+ * Replaces {paramName} placeholders with actual parameter values.
26
+ * Supports nested properties: {user.id}
27
+ *
28
+ * @param template - Key template (e.g., 'user:{id}')
29
+ * @param method - Method being decorated
30
+ * @param args - Method arguments
31
+ * @param namespace - Optional namespace prefix
32
+ * @returns Generated cache key
33
+ *
34
+ * @throws CacheKeyError if parameter is not found or template is invalid
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * generateKey('user:{id}', getUserMethod, ['123']) // 'user:123'
39
+ * generateKey('user:{user.id}', updateMethod, [{ id: '456' }]) // 'user:456'
40
+ * ```
41
+ */
42
+ export declare function generateKey(template: string, method: Function, args: unknown[], namespace?: string): string;
43
+ /**
44
+ * Generates multiple cache keys from templates and method arguments.
45
+ *
46
+ * @param templates - Array of key templates
47
+ * @param method - Method being decorated
48
+ * @param args - Method arguments
49
+ * @param namespace - Optional namespace prefix
50
+ * @returns Array of generated cache keys
51
+ */
52
+ export declare function generateKeys(templates: string[], method: Function, args: unknown[], namespace?: string): string[];
53
+ /**
54
+ * Evaluates tags - either static array or dynamic function.
55
+ *
56
+ * @param tags - Tags definition (array or function)
57
+ * @param args - Method arguments
58
+ * @returns Array of tag names
59
+ */
60
+ export declare function evaluateTags(tags: string[] | ((...args: unknown[]) => string[]) | undefined, args: unknown[]): string[];
61
+ /**
62
+ * Evaluates condition - determines if caching should proceed.
63
+ *
64
+ * @param condition - Condition function
65
+ * @param args - Method arguments
66
+ * @returns true if caching should proceed
67
+ */
68
+ export declare function evaluateCondition(condition: ((...args: unknown[]) => boolean) | undefined, args: unknown[]): boolean;
69
+ //# sourceMappingURL=key-generator.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-generator.util.d.ts","sourceRoot":"","sources":["../../src/decorators/key-generator.util.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;GAKG;AAEH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,EAAE,CAa5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAgBlE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAEhB,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAE,OAAO,EAAE,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAiFR;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EAAE,EAEnB,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAE,OAAO,EAAE,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,EAAE,CAEV;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAUvH;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAMpH"}