@nest-omni/core 4.1.3-1 → 4.1.3-10
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/audit/audit.module.d.ts +10 -0
- package/audit/audit.module.js +15 -0
- package/audit/controllers/audit.controller.d.ts +24 -0
- package/audit/controllers/audit.controller.js +24 -0
- package/audit/decorators/audit-controller.decorator.d.ts +8 -0
- package/audit/decorators/audit-controller.decorator.js +9 -0
- package/audit/decorators/audit-operation.decorator.d.ts +45 -0
- package/audit/decorators/audit-operation.decorator.js +49 -0
- package/audit/decorators/entity-audit.decorator.d.ts +8 -0
- package/audit/decorators/entity-audit.decorator.js +9 -0
- package/audit/dto/audit-log-query.dto.d.ts +3 -0
- package/audit/dto/audit-log-query.dto.js +3 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +3 -0
- package/audit/dto/compare-entities.dto.d.ts +3 -0
- package/audit/dto/compare-entities.dto.js +3 -0
- package/audit/dto/pre-check-restore.dto.d.ts +3 -0
- package/audit/dto/pre-check-restore.dto.js +3 -0
- package/audit/dto/restore-entity.dto.d.ts +3 -0
- package/audit/dto/restore-entity.dto.js +3 -0
- package/audit/entities/entity-audit-log.entity.d.ts +3 -0
- package/audit/entities/entity-audit-log.entity.js +3 -0
- package/audit/entities/entity-transaction.entity.d.ts +3 -0
- package/audit/entities/entity-transaction.entity.js +3 -0
- package/audit/entities/manual-operation-log.entity.d.ts +4 -0
- package/audit/entities/manual-operation-log.entity.js +4 -0
- package/audit/entities/operation-template.entity.d.ts +4 -0
- package/audit/entities/operation-template.entity.js +4 -0
- package/audit/enums/audit.enums.d.ts +17 -2
- package/audit/enums/audit.enums.js +15 -0
- package/audit/index.js +10 -0
- package/audit/interceptors/audit.interceptor.d.ts +15 -0
- package/audit/interceptors/audit.interceptor.js +23 -1
- package/audit/interfaces/audit.interfaces.d.ts +42 -0
- package/audit/services/audit-context.service.d.ts +15 -0
- package/audit/services/audit-context.service.js +15 -0
- package/audit/services/audit-strategy.service.d.ts +6 -0
- package/audit/services/audit-strategy.service.js +13 -0
- package/audit/services/entity-audit.service.d.ts +57 -0
- package/audit/services/entity-audit.service.js +91 -0
- package/audit/services/manual-audit-log.service.d.ts +124 -0
- package/audit/services/manual-audit-log.service.js +138 -0
- package/audit/services/multi-database.service.d.ts +12 -0
- package/audit/services/multi-database.service.js +12 -0
- package/audit/services/operation-description.service.d.ts +59 -0
- package/audit/services/operation-description.service.js +76 -2
- package/audit/services/transaction-audit.service.d.ts +30 -0
- package/audit/services/transaction-audit.service.js +47 -0
- package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
- package/audit/subscribers/entity-audit.subscriber.js +29 -1
- package/cache/cache-metrics.service.d.ts +67 -0
- package/cache/cache-metrics.service.js +68 -4
- package/cache/cache-serialization.service.d.ts +31 -0
- package/cache/cache-serialization.service.js +25 -0
- package/cache/cache.constants.d.ts +9 -0
- package/cache/cache.constants.js +9 -0
- package/cache/cache.health.d.ts +26 -0
- package/cache/cache.health.js +30 -0
- package/cache/cache.module.d.ts +86 -0
- package/cache/cache.module.js +71 -0
- package/cache/cache.service.d.ts +140 -0
- package/cache/cache.service.js +157 -0
- package/cache/cache.warmup.service.d.ts +39 -0
- package/cache/cache.warmup.service.js +32 -0
- package/cache/decorators/cache-evict.decorator.d.ts +47 -0
- package/cache/decorators/cache-evict.decorator.js +56 -0
- package/cache/decorators/cache-put.decorator.d.ts +34 -0
- package/cache/decorators/cache-put.decorator.js +39 -0
- package/cache/decorators/cacheable.decorator.d.ts +40 -0
- package/cache/decorators/cacheable.decorator.js +55 -0
- package/cache/dependencies/callback.dependency.d.ts +33 -0
- package/cache/dependencies/callback.dependency.js +39 -1
- package/cache/dependencies/chain.dependency.d.ts +28 -0
- package/cache/dependencies/chain.dependency.js +34 -0
- package/cache/dependencies/db.dependency.d.ts +45 -0
- package/cache/dependencies/db.dependency.js +48 -1
- package/cache/dependencies/file.dependency.d.ts +32 -0
- package/cache/dependencies/file.dependency.js +34 -0
- package/cache/dependencies/tag.dependency.d.ts +36 -0
- package/cache/dependencies/tag.dependency.js +36 -0
- package/cache/dependencies/time.dependency.d.ts +43 -0
- package/cache/dependencies/time.dependency.js +43 -0
- package/cache/examples/basic-usage.d.ts +15 -0
- package/cache/examples/basic-usage.js +62 -8
- package/cache/index.js +9 -0
- package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
- package/cache/interfaces/cache-options.interface.d.ts +81 -0
- package/cache/interfaces/cache-options.interface.js +6 -0
- package/cache/interfaces/cache-provider.interface.d.ts +78 -0
- package/cache/providers/base-cache.provider.d.ts +14 -0
- package/cache/providers/base-cache.provider.js +16 -0
- package/cache/providers/cls-cache.provider.d.ts +20 -0
- package/cache/providers/cls-cache.provider.js +28 -0
- package/cache/providers/memory-cache.provider.d.ts +23 -0
- package/cache/providers/memory-cache.provider.js +26 -0
- package/cache/providers/redis-cache.provider.d.ts +26 -0
- package/cache/providers/redis-cache.provider.js +29 -0
- package/cache/utils/dependency-manager.util.d.ts +52 -0
- package/cache/utils/dependency-manager.util.js +59 -0
- package/cache/utils/key-generator.util.d.ts +42 -0
- package/cache/utils/key-generator.util.js +53 -1
- package/common/abstract.entity.d.ts +14 -0
- package/common/abstract.entity.js +14 -0
- package/common/boilerplate.polyfill.d.ts +142 -4
- package/common/boilerplate.polyfill.js +24 -100
- package/common/dto/dto-container.d.ts +16 -0
- package/common/dto/dto-container.js +20 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +14 -0
- package/common/dto/dto-extensions.d.ts +11 -0
- package/common/dto/dto-extensions.js +9 -0
- package/common/dto/dto-service-accessor.d.ts +17 -0
- package/common/dto/dto-service-accessor.js +18 -0
- package/common/dto/dto-transformer.d.ts +12 -0
- package/common/dto/dto-transformer.js +9 -0
- package/common/dto/index.js +2 -0
- package/common/examples/paginate-and-map.example.d.ts +6 -0
- package/common/examples/paginate-and-map.example.js +26 -0
- package/common/utils.d.ts +15 -0
- package/common/utils.js +15 -0
- package/constants/language-code.js +1 -0
- package/decorators/field.decorators.js +8 -1
- package/decorators/property.decorators.js +1 -0
- package/decorators/public-route.decorator.js +1 -0
- package/decorators/transform.decorators.d.ts +27 -0
- package/decorators/transform.decorators.js +29 -0
- package/decorators/translate.decorator.js +1 -0
- package/decorators/user.decorator.js +1 -0
- package/decorators/validator.decorators.d.ts +8 -18
- package/decorators/validator.decorators.js +22 -190
- package/filters/constraint-errors.js +1 -0
- package/helpers/common.helper.d.ts +13 -0
- package/helpers/common.helper.js +13 -0
- package/http-client/config/http-client.config.d.ts +15 -0
- package/http-client/config/http-client.config.js +25 -9
- package/http-client/decorators/http-client.decorators.d.ts +63 -0
- package/http-client/decorators/http-client.decorators.js +71 -3
- package/http-client/entities/http-log.entity.d.ts +229 -0
- package/http-client/entities/http-log.entity.js +6 -1
- package/http-client/errors/http-client.errors.d.ts +57 -0
- package/http-client/errors/http-client.errors.js +58 -0
- package/http-client/examples/advanced-usage.example.d.ts +41 -0
- package/http-client/examples/advanced-usage.example.js +68 -24
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
- package/http-client/examples/basic-usage.example.d.ts +60 -0
- package/http-client/examples/basic-usage.example.js +60 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
- package/http-client/examples/multi-api-configuration.example.js +76 -5
- package/http-client/http-client.module.d.ts +13 -0
- package/http-client/http-client.module.js +19 -0
- package/http-client/index.js +8 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
- package/http-client/interfaces/api-client-config.interface.js +3 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
- package/http-client/services/api-client-registry.service.d.ts +57 -0
- package/http-client/services/api-client-registry.service.js +84 -1
- package/http-client/services/cache.service.d.ts +52 -0
- package/http-client/services/cache.service.js +72 -3
- package/http-client/services/circuit-breaker.service.d.ts +46 -0
- package/http-client/services/circuit-breaker.service.js +52 -0
- package/http-client/services/http-client.service.d.ts +67 -0
- package/http-client/services/http-client.service.js +105 -4
- package/http-client/services/http-log-query.service.d.ts +83 -0
- package/http-client/services/http-log-query.service.js +122 -1
- package/http-client/services/http-replay.service.d.ts +101 -0
- package/http-client/services/http-replay.service.js +86 -0
- package/http-client/services/log-cleanup.service.d.ts +63 -0
- package/http-client/services/log-cleanup.service.js +54 -2
- package/http-client/services/logging.service.d.ts +40 -0
- package/http-client/services/logging.service.js +53 -0
- package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
- package/http-client/utils/call-stack-extractor.util.js +48 -0
- package/http-client/utils/context-extractor.util.d.ts +49 -0
- package/http-client/utils/context-extractor.util.js +52 -0
- package/http-client/utils/curl-generator.util.d.ts +21 -0
- package/http-client/utils/curl-generator.util.js +44 -3
- package/http-client/utils/request-id.util.d.ts +18 -0
- package/http-client/utils/request-id.util.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +42 -0
- package/http-client/utils/retry-recorder.util.js +44 -0
- package/i18n/en_US/validation.json +2 -1
- package/i18n/zh_CN/validation.json +2 -1
- package/index.js +8 -0
- package/interceptors/translation-interceptor.service.js +5 -0
- package/package.json +1 -1
- package/providers/context.provider.js +2 -0
- package/providers/generator.provider.d.ts +4 -0
- package/providers/generator.provider.js +4 -0
- package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
- package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
- package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
- package/redis-lock/examples/lock-strategy.examples.js +130 -15
- package/redis-lock/index.d.ts +2 -0
- package/redis-lock/index.js +8 -1
- package/redis-lock/lock-heartbeat.service.d.ts +78 -0
- package/redis-lock/lock-heartbeat.service.js +222 -0
- package/redis-lock/redis-lock.decorator.d.ts +101 -0
- package/redis-lock/redis-lock.decorator.js +120 -0
- package/redis-lock/redis-lock.module.d.ts +66 -0
- package/redis-lock/redis-lock.module.js +175 -70
- package/redis-lock/redis-lock.service.d.ts +260 -0
- package/redis-lock/redis-lock.service.js +244 -4
- package/setup/bootstrap.setup.js +20 -0
- package/setup/mode.setup.d.ts +44 -0
- package/setup/mode.setup.js +44 -0
- package/setup/schedule.decorator.d.ts +227 -0
- package/setup/schedule.decorator.js +219 -6
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +88 -0
- package/shared/serviceRegistryModule.js +9 -1
- package/shared/services/api-config.service.d.ts +3 -0
- package/shared/services/api-config.service.js +20 -9
- package/validator-json/decorators.d.ts +17 -0
- package/validator-json/decorators.js +17 -2
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +30 -2
- package/validator-json/defaultConverters.js +1 -0
- package/validator-json/options.d.ts +23 -0
- package/validators/common-validators.d.ts +143 -0
- package/validators/common-validators.js +249 -0
- package/validators/custom-validate.examples.d.ts +96 -0
- package/validators/custom-validate.examples.js +400 -0
- package/validators/custom-validate.validator.d.ts +134 -0
- package/validators/custom-validate.validator.js +214 -0
- package/validators/index.d.ts +2 -0
- package/validators/index.js +2 -0
- package/validators/is-exists.validator.d.ts +18 -4
- package/validators/is-exists.validator.js +67 -6
- package/validators/is-unique.validator.d.ts +32 -5
- package/validators/is-unique.validator.js +99 -17
- package/validators/skip-empty.validator.d.ts +5 -0
- package/validators/skip-empty.validator.js +5 -0
- package/vault/interfaces/vault-options.interface.d.ts +9 -0
- package/vault/vault-config.loader.d.ts +30 -0
- package/vault/vault-config.loader.js +48 -1
- package/vault/vault-config.service.d.ts +53 -0
- package/vault/vault-config.service.js +57 -0
- package/vault/vault.module.d.ts +4 -0
- package/vault/vault.module.js +4 -0
- package/decorators/examples/validation-decorators.example.d.ts +0 -69
- package/decorators/examples/validation-decorators.example.js +0 -331
package/cache/cache.service.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { CacheOptions, CacheStats } from './interfaces';
|
|
2
2
|
import { CacheLayer } from './interfaces';
|
|
3
3
|
import { ClsCacheProvider, MemoryCacheProvider, RedisCacheProvider } from './providers';
|
|
4
|
+
/**
|
|
5
|
+
* Unified cache service with three-tier architecture
|
|
6
|
+
*
|
|
7
|
+
* L1: CLS (request-level)
|
|
8
|
+
* L2: Memory (process-level)
|
|
9
|
+
* L3: Redis (distributed)
|
|
10
|
+
*
|
|
11
|
+
* Supports automatic fallback, backfill, and dependency-based invalidation.
|
|
12
|
+
*/
|
|
4
13
|
export declare class CacheService {
|
|
5
14
|
private readonly clsProvider;
|
|
6
15
|
private readonly memoryProvider;
|
|
@@ -11,27 +20,158 @@ export declare class CacheService {
|
|
|
11
20
|
private readonly providers;
|
|
12
21
|
private readonly stats;
|
|
13
22
|
constructor(clsProvider: ClsCacheProvider, memoryProvider: MemoryCacheProvider, redisProvider: RedisCacheProvider, enableCompression?: boolean, compressionThreshold?: number);
|
|
23
|
+
/**
|
|
24
|
+
* Get or set cache value with factory function
|
|
25
|
+
*
|
|
26
|
+
* @param key - Cache key
|
|
27
|
+
* @param factory - Function to generate value if not cached
|
|
28
|
+
* @param options - Cache options
|
|
29
|
+
* @returns Cached or generated value
|
|
30
|
+
*/
|
|
14
31
|
getOrSet<T>(key: string, factory: () => Promise<T>, options?: CacheOptions): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Get value from cache with optional layer specification
|
|
34
|
+
*
|
|
35
|
+
* @param key - Cache key
|
|
36
|
+
* @param options - Cache options including layer preference
|
|
37
|
+
* @returns Cached value or null
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Try memory only
|
|
42
|
+
* const data = await this.cacheService.get('user:123', {
|
|
43
|
+
* layers: [CacheLayer.MEMORY]
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Try all layers in order (CLS -> MEMORY -> REDIS)
|
|
47
|
+
* const data = await this.cacheService.get('config:app', {
|
|
48
|
+
* layers: [CacheLayer.CLS, CacheLayer.MEMORY, CacheLayer.REDIS]
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
15
52
|
get<T>(key: string, options?: CacheOptions): Promise<T | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Set value in cache with optional layer specification
|
|
55
|
+
*
|
|
56
|
+
* Supports both new API (CacheOptions) and legacy API (TTL number) for backward compatibility.
|
|
57
|
+
*
|
|
58
|
+
* @param key - Cache key
|
|
59
|
+
* @param value - Value to cache
|
|
60
|
+
* @param options - Cache options including layer selection OR TTL (number) for legacy compatibility
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // New API - Cache in memory only
|
|
65
|
+
* await this.cacheService.set('user:123', userData, {
|
|
66
|
+
* layers: [CacheLayer.MEMORY],
|
|
67
|
+
* ttl: 300000
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Legacy API - TTL as third parameter (still works for backward compatibility)
|
|
71
|
+
* await this.cacheService.set('user:123', userData, 300000);
|
|
72
|
+
*
|
|
73
|
+
* // Cache in all layers (default behavior)
|
|
74
|
+
* await this.cacheService.set('config:app', configData, {
|
|
75
|
+
* layers: [CacheLayer.CLS, CacheLayer.MEMORY, CacheLayer.REDIS],
|
|
76
|
+
* ttl: 3600000
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Cache in Redis only (distributed)
|
|
80
|
+
* await this.cacheService.set('global:settings', settings, {
|
|
81
|
+
* layers: [CacheLayer.REDIS],
|
|
82
|
+
* ttl: 86400000
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
16
86
|
set<T>(key: string, value: T, options?: CacheOptions | number): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Delete value from cache
|
|
89
|
+
*
|
|
90
|
+
* @param key - Cache key or array of keys
|
|
91
|
+
* @param layers - Specific layers to delete from (default: all)
|
|
92
|
+
*/
|
|
17
93
|
del(key: string | string[], layers?: CacheLayer[]): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Delete keys matching pattern
|
|
96
|
+
*
|
|
97
|
+
* @param pattern - Pattern to match (e.g., 'user:*')
|
|
98
|
+
* @param layers - Specific layers to delete from (default: Memory and Redis only)
|
|
99
|
+
*/
|
|
18
100
|
deletePattern(pattern: string, layers?: CacheLayer[]): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Clear all cache
|
|
103
|
+
*
|
|
104
|
+
* @param layers - Specific layers to clear (default: all)
|
|
105
|
+
*/
|
|
19
106
|
clear(layers?: CacheLayer[]): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Invalidate tags (for TagDependency)
|
|
109
|
+
*
|
|
110
|
+
* @param tags - Tags to invalidate
|
|
111
|
+
*/
|
|
20
112
|
invalidateTags(tags: string[]): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Get multiple values
|
|
115
|
+
*
|
|
116
|
+
* @param keys - Array of cache keys
|
|
117
|
+
* @param options - Cache options
|
|
118
|
+
* @returns Array of values (null for missing keys)
|
|
119
|
+
*/
|
|
21
120
|
mget<T>(keys: string[], options?: CacheOptions): Promise<(T | null)[]>;
|
|
121
|
+
/**
|
|
122
|
+
* Set multiple values
|
|
123
|
+
*
|
|
124
|
+
* @param items - Array of key-value pairs
|
|
125
|
+
* @param options - Cache options
|
|
126
|
+
*/
|
|
22
127
|
mset(items: Array<{
|
|
23
128
|
key: string;
|
|
24
129
|
value: any;
|
|
25
130
|
}>, options?: CacheOptions): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Get cache statistics
|
|
133
|
+
*
|
|
134
|
+
* @returns Cache statistics
|
|
135
|
+
*/
|
|
26
136
|
getStats(): CacheStats;
|
|
137
|
+
/**
|
|
138
|
+
* Reset statistics
|
|
139
|
+
*/
|
|
27
140
|
resetStats(): void;
|
|
141
|
+
/**
|
|
142
|
+
* Internal method to set cache value with options
|
|
143
|
+
*/
|
|
28
144
|
private setWithOptions;
|
|
145
|
+
/**
|
|
146
|
+
* Resolve cache layers from options
|
|
147
|
+
*/
|
|
29
148
|
private resolveLayers;
|
|
149
|
+
/**
|
|
150
|
+
* Get default cache layers
|
|
151
|
+
*/
|
|
30
152
|
private getDefaultLayers;
|
|
153
|
+
/**
|
|
154
|
+
* Build full cache key with namespace
|
|
155
|
+
*/
|
|
31
156
|
private buildKey;
|
|
157
|
+
/**
|
|
158
|
+
* Backfill upper cache layers
|
|
159
|
+
*/
|
|
32
160
|
private backfillUpperLayers;
|
|
161
|
+
/**
|
|
162
|
+
* Record cache hit
|
|
163
|
+
*/
|
|
33
164
|
private recordHit;
|
|
165
|
+
/**
|
|
166
|
+
* Record cache miss
|
|
167
|
+
*/
|
|
34
168
|
private recordMiss;
|
|
169
|
+
/**
|
|
170
|
+
* Update hit rate for a layer
|
|
171
|
+
*/
|
|
35
172
|
private updateLayerHitRate;
|
|
173
|
+
/**
|
|
174
|
+
* Initialize statistics for all layers
|
|
175
|
+
*/
|
|
36
176
|
private initializeStats;
|
|
37
177
|
}
|
package/cache/cache.service.js
CHANGED
|
@@ -30,6 +30,15 @@ const providers_1 = require("./providers");
|
|
|
30
30
|
const utils_1 = require("./utils");
|
|
31
31
|
const cache_serialization_service_1 = require("./cache-serialization.service");
|
|
32
32
|
const cache_constants_1 = require("./cache.constants");
|
|
33
|
+
/**
|
|
34
|
+
* Unified cache service with three-tier architecture
|
|
35
|
+
*
|
|
36
|
+
* L1: CLS (request-level)
|
|
37
|
+
* L2: Memory (process-level)
|
|
38
|
+
* L3: Redis (distributed)
|
|
39
|
+
*
|
|
40
|
+
* Supports automatic fallback, backfill, and dependency-based invalidation.
|
|
41
|
+
*/
|
|
33
42
|
let CacheService = CacheService_1 = class CacheService {
|
|
34
43
|
constructor(clsProvider, memoryProvider, redisProvider, enableCompression = false, compressionThreshold = 1024) {
|
|
35
44
|
this.clsProvider = clsProvider;
|
|
@@ -54,22 +63,54 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
54
63
|
this.providers.set(interfaces_1.CacheLayer.REDIS, redisProvider);
|
|
55
64
|
this.initializeStats();
|
|
56
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Get or set cache value with factory function
|
|
68
|
+
*
|
|
69
|
+
* @param key - Cache key
|
|
70
|
+
* @param factory - Function to generate value if not cached
|
|
71
|
+
* @param options - Cache options
|
|
72
|
+
* @returns Cached or generated value
|
|
73
|
+
*/
|
|
57
74
|
getOrSet(key, factory, options) {
|
|
58
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
// Try to get from cache
|
|
59
77
|
const cached = yield this.get(key, options);
|
|
60
78
|
if (cached !== null) {
|
|
61
79
|
return cached;
|
|
62
80
|
}
|
|
81
|
+
// Generate new value
|
|
63
82
|
const value = yield factory();
|
|
83
|
+
// Cache the value
|
|
64
84
|
yield this.set(key, value, options);
|
|
65
85
|
return value;
|
|
66
86
|
});
|
|
67
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Get value from cache with optional layer specification
|
|
90
|
+
*
|
|
91
|
+
* @param key - Cache key
|
|
92
|
+
* @param options - Cache options including layer preference
|
|
93
|
+
* @returns Cached value or null
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Try memory only
|
|
98
|
+
* const data = await this.cacheService.get('user:123', {
|
|
99
|
+
* layers: [CacheLayer.MEMORY]
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Try all layers in order (CLS -> MEMORY -> REDIS)
|
|
103
|
+
* const data = await this.cacheService.get('config:app', {
|
|
104
|
+
* layers: [CacheLayer.CLS, CacheLayer.MEMORY, CacheLayer.REDIS]
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
68
108
|
get(key, options) {
|
|
69
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
110
|
this.stats.totalGets++;
|
|
71
111
|
const layers = this.resolveLayers(options === null || options === void 0 ? void 0 : options.layers);
|
|
72
112
|
const fullKey = this.buildKey(key, options === null || options === void 0 ? void 0 : options.namespace);
|
|
113
|
+
// Try each layer in order
|
|
73
114
|
for (let i = 0; i < layers.length; i++) {
|
|
74
115
|
const layer = layers[i];
|
|
75
116
|
const provider = this.providers.get(layer);
|
|
@@ -79,19 +120,24 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
79
120
|
try {
|
|
80
121
|
const wrapped = yield provider.get(fullKey);
|
|
81
122
|
if (wrapped !== null) {
|
|
123
|
+
// Validate dependencies if present
|
|
82
124
|
let value = yield utils_1.DependencyManager.unwrapAndValidate(wrapped, options === null || options === void 0 ? void 0 : options.dependencies);
|
|
83
125
|
if (value !== null) {
|
|
126
|
+
// Check if value is compressed and decompress if needed
|
|
84
127
|
if (this.enableCompression && Buffer.isBuffer(value)) {
|
|
85
128
|
const serializationService = new cache_serialization_service_1.CacheSerializationService();
|
|
86
129
|
const decompressed = yield serializationService.deserialize(value);
|
|
87
130
|
value = decompressed.data;
|
|
88
131
|
}
|
|
132
|
+
// Cache hit
|
|
89
133
|
this.recordHit(layer);
|
|
134
|
+
// Backfill upper layers
|
|
90
135
|
if ((options === null || options === void 0 ? void 0 : options.backfill) !== false && i > 0) {
|
|
91
136
|
yield this.backfillUpperLayers(fullKey, wrapped, layers.slice(0, i), options === null || options === void 0 ? void 0 : options.ttl);
|
|
92
137
|
}
|
|
93
138
|
return value;
|
|
94
139
|
}
|
|
140
|
+
// Dependencies changed, delete from this layer
|
|
95
141
|
yield provider.delete(fullKey);
|
|
96
142
|
}
|
|
97
143
|
}
|
|
@@ -99,20 +145,63 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
99
145
|
this.logger.warn(`Failed to get from ${layer} cache: ${error instanceof Error ? error.message : String(error)}`);
|
|
100
146
|
}
|
|
101
147
|
}
|
|
148
|
+
// Cache miss
|
|
102
149
|
this.recordMiss();
|
|
103
150
|
return null;
|
|
104
151
|
});
|
|
105
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Set value in cache with optional layer specification
|
|
155
|
+
*
|
|
156
|
+
* Supports both new API (CacheOptions) and legacy API (TTL number) for backward compatibility.
|
|
157
|
+
*
|
|
158
|
+
* @param key - Cache key
|
|
159
|
+
* @param value - Value to cache
|
|
160
|
+
* @param options - Cache options including layer selection OR TTL (number) for legacy compatibility
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // New API - Cache in memory only
|
|
165
|
+
* await this.cacheService.set('user:123', userData, {
|
|
166
|
+
* layers: [CacheLayer.MEMORY],
|
|
167
|
+
* ttl: 300000
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* // Legacy API - TTL as third parameter (still works for backward compatibility)
|
|
171
|
+
* await this.cacheService.set('user:123', userData, 300000);
|
|
172
|
+
*
|
|
173
|
+
* // Cache in all layers (default behavior)
|
|
174
|
+
* await this.cacheService.set('config:app', configData, {
|
|
175
|
+
* layers: [CacheLayer.CLS, CacheLayer.MEMORY, CacheLayer.REDIS],
|
|
176
|
+
* ttl: 3600000
|
|
177
|
+
* });
|
|
178
|
+
*
|
|
179
|
+
* // Cache in Redis only (distributed)
|
|
180
|
+
* await this.cacheService.set('global:settings', settings, {
|
|
181
|
+
* layers: [CacheLayer.REDIS],
|
|
182
|
+
* ttl: 86400000
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
106
186
|
set(key, value, options) {
|
|
107
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
// Check if the third parameter is a number (old API) or CacheOptions (new API)
|
|
108
189
|
if (typeof options === 'number') {
|
|
190
|
+
// Old cache-manager API: set(key, value, ttl)
|
|
109
191
|
return this.setWithOptions(key, value, { ttl: options });
|
|
110
192
|
}
|
|
111
193
|
else {
|
|
194
|
+
// New API: set(key, value, options)
|
|
112
195
|
return this.setWithOptions(key, value, options);
|
|
113
196
|
}
|
|
114
197
|
});
|
|
115
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Delete value from cache
|
|
201
|
+
*
|
|
202
|
+
* @param key - Cache key or array of keys
|
|
203
|
+
* @param layers - Specific layers to delete from (default: all)
|
|
204
|
+
*/
|
|
116
205
|
del(key, layers) {
|
|
117
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
207
|
this.stats.totalDeletes++;
|
|
@@ -133,6 +222,12 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
133
222
|
yield Promise.all(promises);
|
|
134
223
|
});
|
|
135
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Delete keys matching pattern
|
|
227
|
+
*
|
|
228
|
+
* @param pattern - Pattern to match (e.g., 'user:*')
|
|
229
|
+
* @param layers - Specific layers to delete from (default: Memory and Redis only)
|
|
230
|
+
*/
|
|
136
231
|
deletePattern(pattern, layers) {
|
|
137
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
233
|
const targetLayers = layers || [interfaces_1.CacheLayer.MEMORY, interfaces_1.CacheLayer.REDIS];
|
|
@@ -151,6 +246,11 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
151
246
|
yield Promise.all(promises);
|
|
152
247
|
});
|
|
153
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Clear all cache
|
|
251
|
+
*
|
|
252
|
+
* @param layers - Specific layers to clear (default: all)
|
|
253
|
+
*/
|
|
154
254
|
clear(layers) {
|
|
155
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
256
|
this.stats.totalClears++;
|
|
@@ -170,27 +270,53 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
170
270
|
yield Promise.all(promises);
|
|
171
271
|
});
|
|
172
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Invalidate tags (for TagDependency)
|
|
275
|
+
*
|
|
276
|
+
* @param tags - Tags to invalidate
|
|
277
|
+
*/
|
|
173
278
|
invalidateTags(tags) {
|
|
174
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
280
|
dependencies_1.TagDependency.invalidateTags(tags);
|
|
176
281
|
this.logger.debug(`Invalidated tags: ${tags.join(', ')}`);
|
|
177
282
|
});
|
|
178
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Get multiple values
|
|
286
|
+
*
|
|
287
|
+
* @param keys - Array of cache keys
|
|
288
|
+
* @param options - Cache options
|
|
289
|
+
* @returns Array of values (null for missing keys)
|
|
290
|
+
*/
|
|
179
291
|
mget(keys, options) {
|
|
180
292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
293
|
const promises = keys.map((key) => this.get(key, options));
|
|
182
294
|
return Promise.all(promises);
|
|
183
295
|
});
|
|
184
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Set multiple values
|
|
299
|
+
*
|
|
300
|
+
* @param items - Array of key-value pairs
|
|
301
|
+
* @param options - Cache options
|
|
302
|
+
*/
|
|
185
303
|
mset(items, options) {
|
|
186
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
305
|
const promises = items.map((item) => this.set(item.key, item.value, options));
|
|
188
306
|
yield Promise.all(promises);
|
|
189
307
|
});
|
|
190
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Get cache statistics
|
|
311
|
+
*
|
|
312
|
+
* @returns Cache statistics
|
|
313
|
+
*/
|
|
191
314
|
getStats() {
|
|
192
315
|
return Object.assign(Object.assign({}, this.stats), { hitRate: this.stats.totalGets > 0 ? this.stats.hits / this.stats.totalGets : 0 });
|
|
193
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Reset statistics
|
|
319
|
+
*/
|
|
194
320
|
resetStats() {
|
|
195
321
|
this.stats.totalGets = 0;
|
|
196
322
|
this.stats.hits = 0;
|
|
@@ -201,14 +327,19 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
201
327
|
this.stats.totalClears = 0;
|
|
202
328
|
this.initializeStats();
|
|
203
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Internal method to set cache value with options
|
|
332
|
+
*/
|
|
204
333
|
setWithOptions(key, value, options) {
|
|
205
334
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
335
|
this.stats.totalSets++;
|
|
336
|
+
// Check condition
|
|
207
337
|
if ((options === null || options === void 0 ? void 0 : options.condition) && !(yield Promise.resolve(options.condition()))) {
|
|
208
338
|
return;
|
|
209
339
|
}
|
|
210
340
|
const layers = this.resolveLayers(options === null || options === void 0 ? void 0 : options.layers);
|
|
211
341
|
const fullKey = this.buildKey(key, options === null || options === void 0 ? void 0 : options.namespace);
|
|
342
|
+
// Apply compression if enabled and value is large enough
|
|
212
343
|
let processedValue = value;
|
|
213
344
|
if (this.enableCompression &&
|
|
214
345
|
value !== null &&
|
|
@@ -221,7 +352,9 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
221
352
|
});
|
|
222
353
|
processedValue = compressed.data;
|
|
223
354
|
}
|
|
355
|
+
// Wrap value with dependencies
|
|
224
356
|
const wrapped = yield utils_1.DependencyManager.wrapWithDependencies(processedValue, options === null || options === void 0 ? void 0 : options.dependencies);
|
|
357
|
+
// Set in all layers
|
|
225
358
|
const promises = layers.map((layer) => __awaiter(this, void 0, void 0, function* () {
|
|
226
359
|
const provider = this.providers.get(layer);
|
|
227
360
|
if (!provider) {
|
|
@@ -237,21 +370,33 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
237
370
|
yield Promise.all(promises);
|
|
238
371
|
});
|
|
239
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Resolve cache layers from options
|
|
375
|
+
*/
|
|
240
376
|
resolveLayers(layers) {
|
|
241
377
|
if (layers && layers.length > 0) {
|
|
242
378
|
return layers;
|
|
243
379
|
}
|
|
244
380
|
return this.getDefaultLayers();
|
|
245
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Get default cache layers
|
|
384
|
+
*/
|
|
246
385
|
getDefaultLayers() {
|
|
247
386
|
return [interfaces_1.CacheLayer.CLS, interfaces_1.CacheLayer.MEMORY, interfaces_1.CacheLayer.REDIS];
|
|
248
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Build full cache key with namespace
|
|
390
|
+
*/
|
|
249
391
|
buildKey(key, namespace) {
|
|
250
392
|
if (namespace) {
|
|
251
393
|
return `${namespace}:${key}`;
|
|
252
394
|
}
|
|
253
395
|
return key;
|
|
254
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Backfill upper cache layers
|
|
399
|
+
*/
|
|
255
400
|
backfillUpperLayers(key, value, layers, ttl) {
|
|
256
401
|
return __awaiter(this, void 0, void 0, function* () {
|
|
257
402
|
const promises = layers.map((layer) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -269,6 +414,9 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
269
414
|
yield Promise.all(promises);
|
|
270
415
|
});
|
|
271
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Record cache hit
|
|
419
|
+
*/
|
|
272
420
|
recordHit(layer) {
|
|
273
421
|
this.stats.hits++;
|
|
274
422
|
if (!this.stats.byLayer[layer]) {
|
|
@@ -277,9 +425,15 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
277
425
|
this.stats.byLayer[layer].hits++;
|
|
278
426
|
this.updateLayerHitRate(layer);
|
|
279
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* Record cache miss
|
|
430
|
+
*/
|
|
280
431
|
recordMiss() {
|
|
281
432
|
this.stats.misses++;
|
|
282
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Update hit rate for a layer
|
|
436
|
+
*/
|
|
283
437
|
updateLayerHitRate(layer) {
|
|
284
438
|
const layerStats = this.stats.byLayer[layer];
|
|
285
439
|
if (layerStats) {
|
|
@@ -287,6 +441,9 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
287
441
|
layerStats.hitRate = total > 0 ? layerStats.hits / total : 0;
|
|
288
442
|
}
|
|
289
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* Initialize statistics for all layers
|
|
446
|
+
*/
|
|
290
447
|
initializeStats() {
|
|
291
448
|
for (const layer of [interfaces_1.CacheLayer.CLS, interfaces_1.CacheLayer.MEMORY, interfaces_1.CacheLayer.REDIS]) {
|
|
292
449
|
if (!this.stats.byLayer[layer]) {
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { CacheService } from './cache.service';
|
|
2
|
+
/**
|
|
3
|
+
* Cache warmup configuration
|
|
4
|
+
*/
|
|
2
5
|
export interface CacheWarmupConfig {
|
|
6
|
+
/** Warmup task name */
|
|
3
7
|
name: string;
|
|
8
|
+
/** Function to generate cache data */
|
|
4
9
|
dataProvider: () => Promise<any> | any;
|
|
10
|
+
/** Cache key or key generator */
|
|
5
11
|
key: string | ((data: any) => string);
|
|
12
|
+
/** Cache TTL */
|
|
6
13
|
ttl?: number;
|
|
14
|
+
/** Cache layers to use */
|
|
7
15
|
layers?: string[];
|
|
16
|
+
/** Number of items to process in parallel */
|
|
8
17
|
batchSize?: number;
|
|
18
|
+
/** Whether this warmup is critical (fail if it fails) */
|
|
9
19
|
critical?: boolean;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Cache warmup result
|
|
23
|
+
*/
|
|
11
24
|
export interface CacheWarmupResult {
|
|
12
25
|
name: string;
|
|
13
26
|
success: boolean;
|
|
@@ -15,20 +28,46 @@ export interface CacheWarmupResult {
|
|
|
15
28
|
duration: number;
|
|
16
29
|
errors: string[];
|
|
17
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Cache warmup service
|
|
33
|
+
*
|
|
34
|
+
* Provides functionality to warm up cache with data before serving requests
|
|
35
|
+
*/
|
|
18
36
|
export declare class CacheWarmupService {
|
|
19
37
|
private readonly cacheService;
|
|
20
38
|
private readonly logger;
|
|
21
39
|
private warmupConfigs;
|
|
22
40
|
constructor(cacheService: CacheService);
|
|
41
|
+
/**
|
|
42
|
+
* Register warmup configurations for a group
|
|
43
|
+
*/
|
|
23
44
|
registerWarmup(groupName: string, configs: CacheWarmupConfig[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Execute warmup for a specific group
|
|
47
|
+
*/
|
|
24
48
|
warmupGroup(groupName: string): Promise<CacheWarmupResult[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Execute warmup for all registered groups
|
|
51
|
+
*/
|
|
25
52
|
warmupAll(): Promise<Map<string, CacheWarmupResult[]>>;
|
|
53
|
+
/**
|
|
54
|
+
* Get warmup statistics
|
|
55
|
+
*/
|
|
26
56
|
getWarmupStats(): {
|
|
27
57
|
totalGroups: number;
|
|
28
58
|
totalTasks: number;
|
|
29
59
|
taskDetails: any[];
|
|
30
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Remove warmup configuration
|
|
63
|
+
*/
|
|
31
64
|
removeWarmupGroup(groupName: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Clear all warmup configurations
|
|
67
|
+
*/
|
|
32
68
|
clearWarmupConfigs(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Execute a single warmup task
|
|
71
|
+
*/
|
|
33
72
|
private executeWarmupTask;
|
|
34
73
|
}
|
|
@@ -22,16 +22,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.CacheWarmupService = void 0;
|
|
23
23
|
const common_1 = require("@nestjs/common");
|
|
24
24
|
const cache_service_1 = require("./cache.service");
|
|
25
|
+
/**
|
|
26
|
+
* Cache warmup service
|
|
27
|
+
*
|
|
28
|
+
* Provides functionality to warm up cache with data before serving requests
|
|
29
|
+
*/
|
|
25
30
|
let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
26
31
|
constructor(cacheService) {
|
|
27
32
|
this.cacheService = cacheService;
|
|
28
33
|
this.logger = new common_1.Logger(CacheWarmupService_1.name);
|
|
29
34
|
this.warmupConfigs = new Map();
|
|
30
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Register warmup configurations for a group
|
|
38
|
+
*/
|
|
31
39
|
registerWarmup(groupName, configs) {
|
|
32
40
|
this.warmupConfigs.set(groupName, configs);
|
|
33
41
|
this.logger.debug(`Registered ${configs.length} warmup tasks for group: ${groupName}`);
|
|
34
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute warmup for a specific group
|
|
45
|
+
*/
|
|
35
46
|
warmupGroup(groupName) {
|
|
36
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
48
|
const configs = this.warmupConfigs.get(groupName);
|
|
@@ -57,6 +68,9 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
57
68
|
return results;
|
|
58
69
|
});
|
|
59
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Execute warmup for all registered groups
|
|
73
|
+
*/
|
|
60
74
|
warmupAll() {
|
|
61
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
76
|
const results = new Map();
|
|
@@ -81,6 +95,9 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
81
95
|
return results;
|
|
82
96
|
});
|
|
83
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Get warmup statistics
|
|
100
|
+
*/
|
|
84
101
|
getWarmupStats() {
|
|
85
102
|
const totalGroups = this.warmupConfigs.size;
|
|
86
103
|
let totalTasks = 0;
|
|
@@ -98,13 +115,22 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
98
115
|
}
|
|
99
116
|
return { totalGroups, totalTasks, taskDetails };
|
|
100
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove warmup configuration
|
|
120
|
+
*/
|
|
101
121
|
removeWarmupGroup(groupName) {
|
|
102
122
|
return this.warmupConfigs.delete(groupName);
|
|
103
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Clear all warmup configurations
|
|
126
|
+
*/
|
|
104
127
|
clearWarmupConfigs() {
|
|
105
128
|
this.warmupConfigs.clear();
|
|
106
129
|
this.logger.debug('All warmup configurations cleared');
|
|
107
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Execute a single warmup task
|
|
133
|
+
*/
|
|
108
134
|
executeWarmupTask(config) {
|
|
109
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
136
|
const startTime = Date.now();
|
|
@@ -113,8 +139,11 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
113
139
|
let success = true;
|
|
114
140
|
try {
|
|
115
141
|
this.logger.debug(`Executing warmup task: ${config.name}`);
|
|
142
|
+
// Get data from provider
|
|
116
143
|
const data = yield Promise.resolve(config.dataProvider());
|
|
144
|
+
// Handle different data types
|
|
117
145
|
if (Array.isArray(data)) {
|
|
146
|
+
// Array of items - warm up each item
|
|
118
147
|
const batchSize = config.batchSize || 100;
|
|
119
148
|
itemCount = data.length;
|
|
120
149
|
for (let i = 0; i < data.length; i += batchSize) {
|
|
@@ -136,6 +165,7 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
136
165
|
}
|
|
137
166
|
}
|
|
138
167
|
else if (data && typeof data === 'object') {
|
|
168
|
+
// Single object - could be a Map or key-value pairs
|
|
139
169
|
if (data instanceof Map) {
|
|
140
170
|
itemCount = data.size;
|
|
141
171
|
for (const [key, value] of data) {
|
|
@@ -151,6 +181,7 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
151
181
|
}
|
|
152
182
|
}
|
|
153
183
|
else {
|
|
184
|
+
// Single object
|
|
154
185
|
itemCount = 1;
|
|
155
186
|
const key = typeof config.key === 'function' ? config.key(data) : config.key;
|
|
156
187
|
yield this.cacheService.set(key, data, {
|
|
@@ -160,6 +191,7 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
160
191
|
}
|
|
161
192
|
}
|
|
162
193
|
else if (data !== null && data !== undefined) {
|
|
194
|
+
// Primitive value
|
|
163
195
|
itemCount = 1;
|
|
164
196
|
const key = typeof config.key === 'function' ? config.key(data) : config.key;
|
|
165
197
|
yield this.cacheService.set(key, data, {
|