@xbg.solutions/backend-core 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.
- package/lib/core/src/app.d.ts +28 -0
- package/lib/core/src/app.d.ts.map +1 -0
- package/lib/core/src/app.js +188 -0
- package/lib/core/src/app.js.map +1 -0
- package/lib/core/src/base/BaseController.d.ts +108 -0
- package/lib/core/src/base/BaseController.d.ts.map +1 -0
- package/lib/core/src/base/BaseController.js +307 -0
- package/lib/core/src/base/BaseController.js.map +1 -0
- package/lib/core/src/base/BaseEntity.d.ts +92 -0
- package/lib/core/src/base/BaseEntity.d.ts.map +1 -0
- package/lib/core/src/base/BaseEntity.js +143 -0
- package/lib/core/src/base/BaseEntity.js.map +1 -0
- package/lib/core/src/base/BaseRepository.d.ts +124 -0
- package/lib/core/src/base/BaseRepository.d.ts.map +1 -0
- package/lib/core/src/base/BaseRepository.js +414 -0
- package/lib/core/src/base/BaseRepository.js.map +1 -0
- package/lib/core/src/base/BaseService.d.ts +89 -0
- package/lib/core/src/base/BaseService.d.ts.map +1 -0
- package/lib/core/src/base/BaseService.js +342 -0
- package/lib/core/src/base/BaseService.js.map +1 -0
- package/lib/core/src/base/index.d.ts +8 -0
- package/lib/core/src/base/index.d.ts.map +1 -0
- package/lib/core/src/base/index.js +24 -0
- package/lib/core/src/base/index.js.map +1 -0
- package/lib/core/src/config/app.config.d.ts +70 -0
- package/lib/core/src/config/app.config.d.ts.map +1 -0
- package/lib/core/src/config/app.config.js +106 -0
- package/lib/core/src/config/app.config.js.map +1 -0
- package/lib/core/src/config/auth.config.d.ts +54 -0
- package/lib/core/src/config/auth.config.d.ts.map +1 -0
- package/lib/core/src/config/auth.config.js +88 -0
- package/lib/core/src/config/auth.config.js.map +1 -0
- package/lib/core/src/config/cache.config.d.ts +47 -0
- package/lib/core/src/config/cache.config.d.ts.map +1 -0
- package/lib/core/src/config/cache.config.js +225 -0
- package/lib/core/src/config/cache.config.js.map +1 -0
- package/lib/core/src/config/communications.config.d.ts +175 -0
- package/lib/core/src/config/communications.config.d.ts.map +1 -0
- package/lib/core/src/config/communications.config.js +219 -0
- package/lib/core/src/config/communications.config.js.map +1 -0
- package/lib/core/src/config/database.config.d.ts +68 -0
- package/lib/core/src/config/database.config.d.ts.map +1 -0
- package/lib/core/src/config/database.config.js +95 -0
- package/lib/core/src/config/database.config.js.map +1 -0
- package/lib/core/src/config/firebase-event-mapping.config.d.ts +41 -0
- package/lib/core/src/config/firebase-event-mapping.config.d.ts.map +1 -0
- package/lib/core/src/config/firebase-event-mapping.config.js +180 -0
- package/lib/core/src/config/firebase-event-mapping.config.js.map +1 -0
- package/lib/core/src/config/firestore.config.d.ts +61 -0
- package/lib/core/src/config/firestore.config.d.ts.map +1 -0
- package/lib/core/src/config/firestore.config.js +74 -0
- package/lib/core/src/config/firestore.config.js.map +1 -0
- package/lib/core/src/config/index.d.ts +15 -0
- package/lib/core/src/config/index.d.ts.map +1 -0
- package/lib/core/src/config/index.js +41 -0
- package/lib/core/src/config/index.js.map +1 -0
- package/lib/core/src/config/maps.config.d.ts +31 -0
- package/lib/core/src/config/maps.config.d.ts.map +1 -0
- package/lib/core/src/config/maps.config.js +50 -0
- package/lib/core/src/config/maps.config.js.map +1 -0
- package/lib/core/src/config/middleware.config.d.ts +57 -0
- package/lib/core/src/config/middleware.config.d.ts.map +1 -0
- package/lib/core/src/config/middleware.config.js +68 -0
- package/lib/core/src/config/middleware.config.js.map +1 -0
- package/lib/core/src/config/tokens.config.d.ts +53 -0
- package/lib/core/src/config/tokens.config.d.ts.map +1 -0
- package/lib/core/src/config/tokens.config.js +129 -0
- package/lib/core/src/config/tokens.config.js.map +1 -0
- package/lib/core/src/generator/generator.d.ts +38 -0
- package/lib/core/src/generator/generator.d.ts.map +1 -0
- package/lib/core/src/generator/generator.js +159 -0
- package/lib/core/src/generator/generator.js.map +1 -0
- package/lib/core/src/generator/index.d.ts +7 -0
- package/lib/core/src/generator/index.d.ts.map +1 -0
- package/lib/core/src/generator/index.js +23 -0
- package/lib/core/src/generator/index.js.map +1 -0
- package/lib/core/src/generator/parser.d.ts +10 -0
- package/lib/core/src/generator/parser.d.ts.map +1 -0
- package/lib/core/src/generator/parser.js +197 -0
- package/lib/core/src/generator/parser.js.map +1 -0
- package/lib/core/src/generator/types.d.ts +112 -0
- package/lib/core/src/generator/types.d.ts.map +1 -0
- package/lib/core/src/generator/types.js +7 -0
- package/lib/core/src/generator/types.js.map +1 -0
- package/lib/core/src/index.d.ts +19 -0
- package/lib/core/src/index.d.ts.map +1 -0
- package/lib/core/src/index.js +46 -0
- package/lib/core/src/index.js.map +1 -0
- package/lib/core/src/middleware/auth.middleware.d.ts +57 -0
- package/lib/core/src/middleware/auth.middleware.d.ts.map +1 -0
- package/lib/core/src/middleware/auth.middleware.js +256 -0
- package/lib/core/src/middleware/auth.middleware.js.map +1 -0
- package/lib/core/src/middleware/cors.middleware.d.ts +13 -0
- package/lib/core/src/middleware/cors.middleware.d.ts.map +1 -0
- package/lib/core/src/middleware/cors.middleware.js +50 -0
- package/lib/core/src/middleware/cors.middleware.js.map +1 -0
- package/lib/core/src/middleware/error.middleware.d.ts +46 -0
- package/lib/core/src/middleware/error.middleware.d.ts.map +1 -0
- package/lib/core/src/middleware/error.middleware.js +174 -0
- package/lib/core/src/middleware/error.middleware.js.map +1 -0
- package/lib/core/src/middleware/index.d.ts +11 -0
- package/lib/core/src/middleware/index.d.ts.map +1 -0
- package/lib/core/src/middleware/index.js +27 -0
- package/lib/core/src/middleware/index.js.map +1 -0
- package/lib/core/src/middleware/logging.middleware.d.ts +10 -0
- package/lib/core/src/middleware/logging.middleware.d.ts.map +1 -0
- package/lib/core/src/middleware/logging.middleware.js +87 -0
- package/lib/core/src/middleware/logging.middleware.js.map +1 -0
- package/lib/core/src/middleware/rateLimit.middleware.d.ts +26 -0
- package/lib/core/src/middleware/rateLimit.middleware.d.ts.map +1 -0
- package/lib/core/src/middleware/rateLimit.middleware.js +105 -0
- package/lib/core/src/middleware/rateLimit.middleware.js.map +1 -0
- package/lib/core/src/middleware/requestId.middleware.d.ts +11 -0
- package/lib/core/src/middleware/requestId.middleware.d.ts.map +1 -0
- package/lib/core/src/middleware/requestId.middleware.js +26 -0
- package/lib/core/src/middleware/requestId.middleware.js.map +1 -0
- package/lib/core/src/middleware/validation.middleware.d.ts +25 -0
- package/lib/core/src/middleware/validation.middleware.d.ts.map +1 -0
- package/lib/core/src/middleware/validation.middleware.js +133 -0
- package/lib/core/src/middleware/validation.middleware.js.map +1 -0
- package/lib/core/src/types/errors.d.ts +119 -0
- package/lib/core/src/types/errors.d.ts.map +1 -0
- package/lib/core/src/types/errors.js +210 -0
- package/lib/core/src/types/errors.js.map +1 -0
- package/lib/utils-cache-connector/src/cache-connector.d.ts +139 -0
- package/lib/utils-cache-connector/src/cache-connector.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/cache-connector.js +277 -0
- package/lib/utils-cache-connector/src/cache-connector.js.map +1 -0
- package/lib/utils-cache-connector/src/index.d.ts +52 -0
- package/lib/utils-cache-connector/src/index.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/index.js +103 -0
- package/lib/utils-cache-connector/src/index.js.map +1 -0
- package/lib/utils-cache-connector/src/providers/base-cache-provider.d.ts +95 -0
- package/lib/utils-cache-connector/src/providers/base-cache-provider.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/providers/base-cache-provider.js +120 -0
- package/lib/utils-cache-connector/src/providers/base-cache-provider.js.map +1 -0
- package/lib/utils-cache-connector/src/providers/firestore-cache-provider.d.ts +58 -0
- package/lib/utils-cache-connector/src/providers/firestore-cache-provider.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/providers/firestore-cache-provider.js +418 -0
- package/lib/utils-cache-connector/src/providers/firestore-cache-provider.js.map +1 -0
- package/lib/utils-cache-connector/src/providers/memory-cache-provider.d.ts +57 -0
- package/lib/utils-cache-connector/src/providers/memory-cache-provider.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/providers/memory-cache-provider.js +217 -0
- package/lib/utils-cache-connector/src/providers/memory-cache-provider.js.map +1 -0
- package/lib/utils-cache-connector/src/providers/noop-cache-provider.d.ts +21 -0
- package/lib/utils-cache-connector/src/providers/noop-cache-provider.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/providers/noop-cache-provider.js +42 -0
- package/lib/utils-cache-connector/src/providers/noop-cache-provider.js.map +1 -0
- package/lib/utils-cache-connector/src/providers/redis-cache-provider.d.ts +64 -0
- package/lib/utils-cache-connector/src/providers/redis-cache-provider.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/providers/redis-cache-provider.js +414 -0
- package/lib/utils-cache-connector/src/providers/redis-cache-provider.js.map +1 -0
- package/lib/utils-cache-connector/src/types.d.ts +342 -0
- package/lib/utils-cache-connector/src/types.d.ts.map +1 -0
- package/lib/utils-cache-connector/src/types.js +8 -0
- package/lib/utils-cache-connector/src/types.js.map +1 -0
- package/lib/utils-events/src/event-bus.d.ts +42 -0
- package/lib/utils-events/src/event-bus.d.ts.map +1 -0
- package/lib/utils-events/src/event-bus.js +93 -0
- package/lib/utils-events/src/event-bus.js.map +1 -0
- package/lib/utils-events/src/event-types.d.ts +146 -0
- package/lib/utils-events/src/event-types.d.ts.map +1 -0
- package/lib/utils-events/src/event-types.js +49 -0
- package/lib/utils-events/src/event-types.js.map +1 -0
- package/lib/utils-events/src/index.d.ts +7 -0
- package/lib/utils-events/src/index.d.ts.map +1 -0
- package/lib/utils-events/src/index.js +11 -0
- package/lib/utils-events/src/index.js.map +1 -0
- package/lib/utils-logger/src/index.d.ts +12 -0
- package/lib/utils-logger/src/index.d.ts.map +1 -0
- package/lib/utils-logger/src/index.js +29 -0
- package/lib/utils-logger/src/index.js.map +1 -0
- package/lib/utils-logger/src/logger-types.d.ts +32 -0
- package/lib/utils-logger/src/logger-types.d.ts.map +1 -0
- package/lib/utils-logger/src/logger-types.js +17 -0
- package/lib/utils-logger/src/logger-types.js.map +1 -0
- package/lib/utils-logger/src/logger.d.ts +42 -0
- package/lib/utils-logger/src/logger.d.ts.map +1 -0
- package/lib/utils-logger/src/logger.js +123 -0
- package/lib/utils-logger/src/logger.js.map +1 -0
- package/package.json +49 -0
- package/src/templates/controller.hbs +48 -0
- package/src/templates/entity.hbs +80 -0
- package/src/templates/repository.hbs +56 -0
- package/src/templates/service.hbs +108 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cache Connector
|
|
4
|
+
*
|
|
5
|
+
* Main facade class for the caching system.
|
|
6
|
+
* Provides a unified API for all cache operations and manages multiple cache providers.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Multi-provider support (memory, firestore, redis)
|
|
10
|
+
* - Lazy provider initialization
|
|
11
|
+
* - Global enable/disable switch
|
|
12
|
+
* - Provider-specific routing
|
|
13
|
+
* - Automatic fallback to no-op when disabled
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const cache = getCacheConnector();
|
|
18
|
+
* await cache.set('key', value, { ttl: 300, provider: 'memory' });
|
|
19
|
+
* const cached = await cache.get<User>('key', { provider: 'memory' });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.CacheConnector = void 0;
|
|
24
|
+
const noop_cache_provider_1 = require("./providers/noop-cache-provider");
|
|
25
|
+
const memory_cache_provider_1 = require("./providers/memory-cache-provider");
|
|
26
|
+
const firestore_cache_provider_1 = require("./providers/firestore-cache-provider");
|
|
27
|
+
const redis_cache_provider_1 = require("./providers/redis-cache-provider");
|
|
28
|
+
const utils_logger_1 = require("@xbg/utils-logger");
|
|
29
|
+
class CacheConnector {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.config = config;
|
|
32
|
+
this.providers = new Map();
|
|
33
|
+
this.noopProvider = new noop_cache_provider_1.NoOpCacheProvider();
|
|
34
|
+
utils_logger_1.logger.info('CacheConnector initialized', {
|
|
35
|
+
operation: 'cache.init',
|
|
36
|
+
enabled: config.enabled,
|
|
37
|
+
defaultProvider: config.defaultProvider,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if caching is enabled globally
|
|
42
|
+
*/
|
|
43
|
+
isEnabled() {
|
|
44
|
+
return this.config.enabled;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get or create a provider instance
|
|
48
|
+
*/
|
|
49
|
+
getProvider(type) {
|
|
50
|
+
// If global cache disabled, always return no-op
|
|
51
|
+
if (!this.config.enabled) {
|
|
52
|
+
return this.noopProvider;
|
|
53
|
+
}
|
|
54
|
+
// Check if provider already exists
|
|
55
|
+
if (this.providers.has(type)) {
|
|
56
|
+
return this.providers.get(type);
|
|
57
|
+
}
|
|
58
|
+
// Create new provider instance
|
|
59
|
+
try {
|
|
60
|
+
const provider = this.createProvider(type);
|
|
61
|
+
this.providers.set(type, provider);
|
|
62
|
+
utils_logger_1.logger.debug(`Cache provider created: ${type}`, {
|
|
63
|
+
operation: 'cache.createProvider',
|
|
64
|
+
provider: type,
|
|
65
|
+
});
|
|
66
|
+
return provider;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
utils_logger_1.logger.error(`Failed to create cache provider: ${type}`, error, {
|
|
70
|
+
operation: 'cache.createProvider',
|
|
71
|
+
provider: type,
|
|
72
|
+
});
|
|
73
|
+
// Fallback to no-op on error
|
|
74
|
+
return this.noopProvider;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a new provider instance based on type
|
|
79
|
+
*/
|
|
80
|
+
createProvider(type) {
|
|
81
|
+
switch (type) {
|
|
82
|
+
case 'memory':
|
|
83
|
+
return new memory_cache_provider_1.MemoryCacheProvider(this.config.providers.memory);
|
|
84
|
+
case 'firestore':
|
|
85
|
+
return new firestore_cache_provider_1.FirestoreCacheProvider(this.config.providers.firestore);
|
|
86
|
+
case 'redis':
|
|
87
|
+
if (!this.config.providers.redis) {
|
|
88
|
+
throw new Error('Redis provider configuration not found');
|
|
89
|
+
}
|
|
90
|
+
return new redis_cache_provider_1.RedisCacheProvider(this.config.providers.redis);
|
|
91
|
+
case 'noop':
|
|
92
|
+
return this.noopProvider;
|
|
93
|
+
default:
|
|
94
|
+
throw new Error(`Unknown cache provider type: ${type}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Resolve provider from options or use default
|
|
99
|
+
*/
|
|
100
|
+
resolveProvider(providerType) {
|
|
101
|
+
const type = providerType || this.config.defaultProvider;
|
|
102
|
+
return this.getProvider(type);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get a value from cache
|
|
106
|
+
*
|
|
107
|
+
* @param key - Cache key
|
|
108
|
+
* @param options - Get options (provider override, metadata, etc.)
|
|
109
|
+
* @returns Cached value or null if not found/expired
|
|
110
|
+
*/
|
|
111
|
+
async get(key, options = {}) {
|
|
112
|
+
const provider = this.resolveProvider(options.provider);
|
|
113
|
+
return provider.get(key);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get a value with metadata from cache
|
|
117
|
+
*
|
|
118
|
+
* @param key - Cache key
|
|
119
|
+
* @param options - Get options
|
|
120
|
+
* @returns Cache entry with metadata or null
|
|
121
|
+
*/
|
|
122
|
+
async getWithMetadata(key, options = {}) {
|
|
123
|
+
const provider = this.resolveProvider(options.provider);
|
|
124
|
+
return provider.getWithMetadata(key);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Set a value in cache
|
|
128
|
+
*
|
|
129
|
+
* @param key - Cache key
|
|
130
|
+
* @param value - Value to cache
|
|
131
|
+
* @param options - Set options (TTL, tags, provider, etc.)
|
|
132
|
+
*/
|
|
133
|
+
async set(key, value, options = {}) {
|
|
134
|
+
const provider = this.resolveProvider(options.provider);
|
|
135
|
+
const ttl = options.ttl || this.config.defaultTTL;
|
|
136
|
+
return provider.set(key, value, Object.assign(Object.assign({}, options), { ttl }));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Delete a specific cache entry
|
|
140
|
+
*
|
|
141
|
+
* @param key - Cache key to delete
|
|
142
|
+
* @param options - Invalidate options
|
|
143
|
+
* @returns True if entry was deleted
|
|
144
|
+
*/
|
|
145
|
+
async delete(key, options = {}) {
|
|
146
|
+
const provider = this.resolveProvider(options.provider);
|
|
147
|
+
return provider.delete(key);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Check if a cache entry exists
|
|
151
|
+
*
|
|
152
|
+
* @param key - Cache key to check
|
|
153
|
+
* @param options - Get options
|
|
154
|
+
* @returns True if entry exists and is not expired
|
|
155
|
+
*/
|
|
156
|
+
async has(key, options = {}) {
|
|
157
|
+
const provider = this.resolveProvider(options.provider);
|
|
158
|
+
return provider.has(key);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Invalidate cache entries by tags
|
|
162
|
+
*
|
|
163
|
+
* @param tags - Array of tags to invalidate
|
|
164
|
+
* @param options - Invalidate options
|
|
165
|
+
* @returns Number of entries invalidated
|
|
166
|
+
*/
|
|
167
|
+
async invalidateByTags(tags, options = {}) {
|
|
168
|
+
const provider = this.resolveProvider(options.provider);
|
|
169
|
+
return provider.invalidateByTags(tags);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Invalidate cache entries by key pattern
|
|
173
|
+
*
|
|
174
|
+
* @param pattern - Pattern to match
|
|
175
|
+
* @param options - Invalidate options
|
|
176
|
+
* @returns Number of entries invalidated
|
|
177
|
+
*/
|
|
178
|
+
async invalidateByPattern(pattern, options = {}) {
|
|
179
|
+
const provider = this.resolveProvider(options.provider);
|
|
180
|
+
const mode = (options.pattern === 'prefix' || options.pattern === 'suffix' || options.pattern === 'contains')
|
|
181
|
+
? options.pattern
|
|
182
|
+
: 'prefix';
|
|
183
|
+
return provider.invalidateByPattern(pattern, mode);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Clear all cache entries
|
|
187
|
+
*
|
|
188
|
+
* @param options - Invalidate options
|
|
189
|
+
*/
|
|
190
|
+
async clear(options = {}) {
|
|
191
|
+
const provider = this.resolveProvider(options.provider);
|
|
192
|
+
return provider.clear();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Clear all cache entries across all providers
|
|
196
|
+
*/
|
|
197
|
+
async clearAll() {
|
|
198
|
+
const providers = Array.from(this.providers.values());
|
|
199
|
+
await Promise.all(providers.map(async (provider) => {
|
|
200
|
+
try {
|
|
201
|
+
await provider.clear();
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
utils_logger_1.logger.error(`Failed to clear cache for provider: ${provider.getType()}`, error, {
|
|
205
|
+
operation: 'cache.clearAll',
|
|
206
|
+
provider: provider.getType(),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get cache statistics
|
|
213
|
+
*
|
|
214
|
+
* @param options - Get options
|
|
215
|
+
* @returns Cache statistics
|
|
216
|
+
*/
|
|
217
|
+
async getStats(options = {}) {
|
|
218
|
+
const provider = this.resolveProvider(options.provider);
|
|
219
|
+
return provider.getStats();
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get statistics for all active providers
|
|
223
|
+
*/
|
|
224
|
+
async getAllStats() {
|
|
225
|
+
const stats = {};
|
|
226
|
+
for (const [type, provider] of this.providers.entries()) {
|
|
227
|
+
try {
|
|
228
|
+
stats[type] = await provider.getStats();
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
utils_logger_1.logger.error(`Failed to get stats for provider: ${type}`, error, {
|
|
232
|
+
operation: 'cache.getAllStats',
|
|
233
|
+
provider: type,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return stats;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Manually trigger cleanup of expired entries
|
|
241
|
+
*
|
|
242
|
+
* @param options - Get options
|
|
243
|
+
* @returns Number of entries cleaned up
|
|
244
|
+
*/
|
|
245
|
+
async cleanup(options = {}) {
|
|
246
|
+
const provider = this.resolveProvider(options.provider);
|
|
247
|
+
if ('cleanup' in provider && typeof provider.cleanup === 'function') {
|
|
248
|
+
return provider.cleanup();
|
|
249
|
+
}
|
|
250
|
+
return 0;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Build a namespaced cache key
|
|
254
|
+
*
|
|
255
|
+
* @param parts - Key parts to join
|
|
256
|
+
* @returns Namespaced cache key
|
|
257
|
+
*/
|
|
258
|
+
buildKey(...parts) {
|
|
259
|
+
return `${this.config.namespace}:${parts.join(':')}`;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Destroy all providers and cleanup resources
|
|
263
|
+
*/
|
|
264
|
+
destroy() {
|
|
265
|
+
for (const provider of this.providers.values()) {
|
|
266
|
+
if ('destroy' in provider && typeof provider.destroy === 'function') {
|
|
267
|
+
provider.destroy();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
this.providers.clear();
|
|
271
|
+
utils_logger_1.logger.info('CacheConnector destroyed', {
|
|
272
|
+
operation: 'cache.destroy',
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.CacheConnector = CacheConnector;
|
|
277
|
+
//# sourceMappingURL=cache-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-connector.js","sourceRoot":"","sources":["../../../../utils-cache-connector/src/cache-connector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAYH,yEAAoE;AACpE,6EAAwE;AACxE,mFAA8E;AAC9E,2EAAsE;AACtE,oDAA2C;AAE3C,MAAa,cAAc;IAIzB,YAAoB,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;QACrC,IAAI,C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AgB,CAAC,OAAO,EAAE,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAEvB,qBAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE;YACtC,SAAS,EAAE,eAAe;SAC3B,CAAC,CAAC;IACL,CAAC;CACF;AA3RD,wCA2RC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Connector
|
|
3
|
+
*
|
|
4
|
+
* Multi-level caching system with pluggable providers.
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Project-level control (global enable/disable)
|
|
8
|
+
* - Repository-level granularity (per-entity provider selection)
|
|
9
|
+
* - Multiple providers (memory, firestore, redis)
|
|
10
|
+
* - Tag-based invalidation
|
|
11
|
+
* - TTL-based expiration
|
|
12
|
+
* - Statistics and monitoring
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Get singleton instance
|
|
17
|
+
* const cache = getCacheConnector();
|
|
18
|
+
*
|
|
19
|
+
* // Set a value
|
|
20
|
+
* await cache.set('user:123', user, { ttl: 300, provider: 'memory' });
|
|
21
|
+
*
|
|
22
|
+
* // Get a value
|
|
23
|
+
* const user = await cache.get<User>('user:123', { provider: 'memory' });
|
|
24
|
+
*
|
|
25
|
+
* // Invalidate by tags
|
|
26
|
+
* await cache.invalidateByTags(['users', 'user:123']);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { CacheConnector } from './cache-connector';
|
|
30
|
+
import { CacheConfig } from './types';
|
|
31
|
+
/**
|
|
32
|
+
* Initialize the cache connector with configuration
|
|
33
|
+
* Call this once during app startup before using getCacheConnector()
|
|
34
|
+
*/
|
|
35
|
+
export declare function initializeCacheConnector(config: CacheConfig): CacheConnector;
|
|
36
|
+
/**
|
|
37
|
+
* Get the singleton CacheConnector instance
|
|
38
|
+
* Throws if not initialized - call initializeCacheConnector() first
|
|
39
|
+
*/
|
|
40
|
+
export declare function getCacheConnector(): CacheConnector;
|
|
41
|
+
/**
|
|
42
|
+
* Reset the cache connector instance (useful for testing)
|
|
43
|
+
*/
|
|
44
|
+
export declare function resetCacheConnector(): void;
|
|
45
|
+
export { CacheConnector } from './cache-connector';
|
|
46
|
+
export * from './types';
|
|
47
|
+
export { BaseCacheProvider } from './providers/base-cache-provider';
|
|
48
|
+
export { NoOpCacheProvider } from './providers/noop-cache-provider';
|
|
49
|
+
export { MemoryCacheProvider } from './providers/memory-cache-provider';
|
|
50
|
+
export { FirestoreCacheProvider } from './providers/firestore-cache-provider';
|
|
51
|
+
export { RedisCacheProvider } from './providers/redis-cache-provider';
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../utils-cache-connector/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,WAAW,GAAG,cAAc,CAM5E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAYlD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAK1C;AAGD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cache Connector
|
|
4
|
+
*
|
|
5
|
+
* Multi-level caching system with pluggable providers.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Project-level control (global enable/disable)
|
|
9
|
+
* - Repository-level granularity (per-entity provider selection)
|
|
10
|
+
* - Multiple providers (memory, firestore, redis)
|
|
11
|
+
* - Tag-based invalidation
|
|
12
|
+
* - TTL-based expiration
|
|
13
|
+
* - Statistics and monitoring
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Get singleton instance
|
|
18
|
+
* const cache = getCacheConnector();
|
|
19
|
+
*
|
|
20
|
+
* // Set a value
|
|
21
|
+
* await cache.set('user:123', user, { ttl: 300, provider: 'memory' });
|
|
22
|
+
*
|
|
23
|
+
* // Get a value
|
|
24
|
+
* const user = await cache.get<User>('user:123', { provider: 'memory' });
|
|
25
|
+
*
|
|
26
|
+
* // Invalidate by tags
|
|
27
|
+
* await cache.invalidateByTags(['users', 'user:123']);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
33
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
34
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(o, k2, desc);
|
|
37
|
+
}) : (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
o[k2] = m[k];
|
|
40
|
+
}));
|
|
41
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
42
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.RedisCacheProvider = exports.FirestoreCacheProvider = exports.MemoryCacheProvider = exports.NoOpCacheProvider = exports.BaseCacheProvider = exports.CacheConnector = void 0;
|
|
46
|
+
exports.initializeCacheConnector = initializeCacheConnector;
|
|
47
|
+
exports.getCacheConnector = getCacheConnector;
|
|
48
|
+
exports.resetCacheConnector = resetCacheConnector;
|
|
49
|
+
const cache_connector_1 = require("./cache-connector");
|
|
50
|
+
// Singleton instance
|
|
51
|
+
let cacheConnectorInstance = null;
|
|
52
|
+
/**
|
|
53
|
+
* Initialize the cache connector with configuration
|
|
54
|
+
* Call this once during app startup before using getCacheConnector()
|
|
55
|
+
*/
|
|
56
|
+
function initializeCacheConnector(config) {
|
|
57
|
+
if (cacheConnectorInstance) {
|
|
58
|
+
cacheConnectorInstance.destroy();
|
|
59
|
+
}
|
|
60
|
+
cacheConnectorInstance = new cache_connector_1.CacheConnector(config);
|
|
61
|
+
return cacheConnectorInstance;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the singleton CacheConnector instance
|
|
65
|
+
* Throws if not initialized - call initializeCacheConnector() first
|
|
66
|
+
*/
|
|
67
|
+
function getCacheConnector() {
|
|
68
|
+
if (!cacheConnectorInstance) {
|
|
69
|
+
// Create with defaults if not explicitly initialized
|
|
70
|
+
cacheConnectorInstance = new cache_connector_1.CacheConnector({
|
|
71
|
+
enabled: false,
|
|
72
|
+
defaultProvider: 'noop',
|
|
73
|
+
defaultTTL: 300,
|
|
74
|
+
namespace: 'app',
|
|
75
|
+
providers: {},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return cacheConnectorInstance;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Reset the cache connector instance (useful for testing)
|
|
82
|
+
*/
|
|
83
|
+
function resetCacheConnector() {
|
|
84
|
+
if (cacheConnectorInstance) {
|
|
85
|
+
cacheConnectorInstance.destroy();
|
|
86
|
+
cacheConnectorInstance = null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Export types and classes
|
|
90
|
+
var cache_connector_2 = require("./cache-connector");
|
|
91
|
+
Object.defineProperty(exports, "CacheConnector", { enumerable: true, get: function () { return cache_connector_2.CacheConnector; } });
|
|
92
|
+
__exportStar(require("./types"), exports);
|
|
93
|
+
var base_cache_provider_1 = require("./providers/base-cache-provider");
|
|
94
|
+
Object.defineProperty(exports, "BaseCacheProvider", { enumerable: true, get: function () { return base_cache_provider_1.BaseCacheProvider; } });
|
|
95
|
+
var noop_cache_provider_1 = require("./providers/noop-cache-provider");
|
|
96
|
+
Object.defineProperty(exports, "NoOpCacheProvider", { enumerable: true, get: function () { return noop_cache_provider_1.NoOpCacheProvider; } });
|
|
97
|
+
var memory_cache_provider_1 = require("./providers/memory-cache-provider");
|
|
98
|
+
Object.defineProperty(exports, "MemoryCacheProvider", { enumerable: true, get: function () { return memory_cache_provider_1.MemoryCacheProvider; } });
|
|
99
|
+
var firestore_cache_provider_1 = require("./providers/firestore-cache-provider");
|
|
100
|
+
Object.defineProperty(exports, "FirestoreCacheProvider", { enumerable: true, get: function () { return firestore_cache_provider_1.FirestoreCacheProvider; } });
|
|
101
|
+
var redis_cache_provider_1 = require("./providers/redis-cache-provider");
|
|
102
|
+
Object.defineProperty(exports, "RedisCacheProvider", { enumerable: true, get: function () { return redis_cache_provider_1.RedisCacheProvider; } });
|
|
103
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../utils-cache-connector/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;;;;;;;;;;;;;;;AAYH,4DAMC;AAMD,8CAYC;AAKD,kDAKC;AA5CD,uDAAmD;AAGnD,qBAAqB;AACrB,IAAI,sBAAsB,GAA0B,IAAI,CAAC;AAEzD;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,MAAmB;IAC1D,IAAI,sBAAsB,EAAE,CAAC;QAC3B,sBAAsB,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;IACD,sBAAsB,GAAG,IAAI,gCAAc,CAAC,MAAM,CAAC,CAAC;IACpD,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,qDAAqD;QACrD,sBAAsB,GAAG,IAAI,gCAAc,CAAC;YAC1C,OAAO,EAAE,KAAK;YACd,eAAe,EAAE,MAAa;YAC9B,UAAU,EAAE,GAAG;YACf,SAAS,EAAE,KAAK;YAChB,SAAS,EAAE,EAAS;SACrB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB;IACjC,IAAI,sBAAsB,EAAE,CAAC;QAC3B,sBAAsB,CAAC,OAAO,EAAE,CAAC;QACjC,sBAAsB,GAAG,IAAI,CAAC;IAChC,CAAC;AACH,CAAC;AAED,2BAA2B;AAC3B,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,0CAAwB;AACxB,uEAAoE;AAA3D,wHAAA,iBAAiB,OAAA;AAC1B,uEAAoE;AAA3D,wHAAA,iBAAiB,OAAA;AAC1B,2EAAwE;AAA/D,4HAAA,mBAAmB,OAAA;AAC5B,iFAA8E;AAArE,kIAAA,sBAAsB,OAAA;AAC/B,yEAAsE;AAA7D,0HAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Cache Provider
|
|
3
|
+
*
|
|
4
|
+
* Abstract base class that all cache providers extend.
|
|
5
|
+
* Provides common functionality and enforces interface compliance.
|
|
6
|
+
*/
|
|
7
|
+
import { CacheProviderType, ICacheProvider, CacheSetOptions, CacheEntry, CacheStats, CacheEntryMetadata } from '../types';
|
|
8
|
+
export declare abstract class BaseCacheProvider implements ICacheProvider {
|
|
9
|
+
protected stats: CacheStats;
|
|
10
|
+
/**
|
|
11
|
+
* Get the provider type
|
|
12
|
+
*/
|
|
13
|
+
abstract getType(): CacheProviderType;
|
|
14
|
+
/**
|
|
15
|
+
* Get a value from cache
|
|
16
|
+
*/
|
|
17
|
+
abstract get<T>(key: string): Promise<T | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Get a value with metadata
|
|
20
|
+
*/
|
|
21
|
+
abstract getWithMetadata<T>(key: string): Promise<CacheEntry<T> | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Set a value in cache
|
|
24
|
+
*/
|
|
25
|
+
abstract set<T>(key: string, value: T, options?: CacheSetOptions): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Delete a specific key
|
|
28
|
+
*/
|
|
29
|
+
abstract delete(key: string): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a key exists
|
|
32
|
+
*/
|
|
33
|
+
abstract has(key: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Invalidate cache entries by tags
|
|
36
|
+
*/
|
|
37
|
+
abstract invalidateByTags(tags: string[]): Promise<number>;
|
|
38
|
+
/**
|
|
39
|
+
* Invalidate cache entries by pattern
|
|
40
|
+
*/
|
|
41
|
+
abstract invalidateByPattern(pattern: string, mode?: 'prefix' | 'suffix' | 'contains'): Promise<number>;
|
|
42
|
+
/**
|
|
43
|
+
* Clear all cache entries
|
|
44
|
+
*/
|
|
45
|
+
abstract clear(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Get cache statistics
|
|
48
|
+
*/
|
|
49
|
+
getStats(): Promise<CacheStats>;
|
|
50
|
+
/**
|
|
51
|
+
* Record a cache hit
|
|
52
|
+
*/
|
|
53
|
+
protected recordHit(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Record a cache miss
|
|
56
|
+
*/
|
|
57
|
+
protected recordMiss(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Record an eviction
|
|
60
|
+
*/
|
|
61
|
+
protected recordEviction(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Record an expiration
|
|
64
|
+
*/
|
|
65
|
+
protected recordExpiration(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Update entry count
|
|
68
|
+
*/
|
|
69
|
+
protected updateEntryCount(count: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* Update cache size
|
|
72
|
+
*/
|
|
73
|
+
protected updateSize(size: number): void;
|
|
74
|
+
/**
|
|
75
|
+
* Check if an entry is expired
|
|
76
|
+
*/
|
|
77
|
+
protected isExpired(expiresAt: Date): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Calculate TTL in milliseconds
|
|
80
|
+
*/
|
|
81
|
+
protected calculateExpiresAt(ttl: number): Date;
|
|
82
|
+
/**
|
|
83
|
+
* Create cache entry metadata
|
|
84
|
+
*/
|
|
85
|
+
protected createMetadata(ttl: number, tags?: string[]): CacheEntryMetadata;
|
|
86
|
+
/**
|
|
87
|
+
* Estimate size of a value in bytes
|
|
88
|
+
*/
|
|
89
|
+
protected estimateSize(value: any): number;
|
|
90
|
+
/**
|
|
91
|
+
* Match key against pattern
|
|
92
|
+
*/
|
|
93
|
+
protected matchPattern(key: string, pattern: string, mode: 'prefix' | 'suffix' | 'contains'): boolean;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=base-cache-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-cache-provider.d.ts","sourceRoot":"","sources":["../../../../../utils-cache-connector/src/providers/base-cache-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,UAAU,EACV,UAAU,EACV,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,8BAAsB,iBAAkB,YAAW,cAAc;IAC/D,SAAS,CAAC,KAAK,EAAE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AAI;IAIlC;;OAEG;IACH,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI/C;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxC;;OAEG;IACH,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,GAAG,OAAO;IAI7C;;OAEG;IACH,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI/C;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,kBAAkB;IAW9E;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM;IAQ1C;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO;CAYtG"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base Cache Provider
|
|
4
|
+
*
|
|
5
|
+
* Abstract base class that all cache providers extend.
|
|
6
|
+
* Provides common functionality and enforces interface compliance.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BaseCacheProvider = void 0;
|
|
10
|
+
class BaseCacheProvider {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.stats = {
|
|
13
|
+
hits: 0,
|
|
14
|
+
misses: 0,
|
|
15
|
+
hitRatio: 0,
|
|
16
|
+
entryCount: 0,
|
|
17
|
+
size: 0,
|
|
18
|
+
evictions: 0,
|
|
19
|
+
expirations: 0,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get cache statistics
|
|
24
|
+
*/
|
|
25
|
+
async getStats() {
|
|
26
|
+
// Calculate hit ratio
|
|
27
|
+
const total = this.stats.hits + this.stats.misses;
|
|
28
|
+
this.stats.hitRatio = total > 0 ? this.stats.hits / total : 0;
|
|
29
|
+
return Object.assign({}, this.stats);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Record a cache hit
|
|
33
|
+
*/
|
|
34
|
+
recordHit() {
|
|
35
|
+
this.stats.hits++;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Record a cache miss
|
|
39
|
+
*/
|
|
40
|
+
recordMiss() {
|
|
41
|
+
this.stats.misses++;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Record an eviction
|
|
45
|
+
*/
|
|
46
|
+
recordEviction() {
|
|
47
|
+
this.stats.evictions++;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Record an expiration
|
|
51
|
+
*/
|
|
52
|
+
recordExpiration() {
|
|
53
|
+
this.stats.expirations++;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Update entry count
|
|
57
|
+
*/
|
|
58
|
+
updateEntryCount(count) {
|
|
59
|
+
this.stats.entryCount = count;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Update cache size
|
|
63
|
+
*/
|
|
64
|
+
updateSize(size) {
|
|
65
|
+
this.stats.size = size;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if an entry is expired
|
|
69
|
+
*/
|
|
70
|
+
isExpired(expiresAt) {
|
|
71
|
+
return expiresAt.getTime() < Date.now();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Calculate TTL in milliseconds
|
|
75
|
+
*/
|
|
76
|
+
calculateExpiresAt(ttl) {
|
|
77
|
+
return new Date(Date.now() + ttl * 1000);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create cache entry metadata
|
|
81
|
+
*/
|
|
82
|
+
createMetadata(ttl, tags = []) {
|
|
83
|
+
const now = new Date();
|
|
84
|
+
return {
|
|
85
|
+
createdAt: now,
|
|
86
|
+
expiresAt: this.calculateExpiresAt(ttl),
|
|
87
|
+
hitCount: 0,
|
|
88
|
+
lastAccessedAt: now,
|
|
89
|
+
tags,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Estimate size of a value in bytes
|
|
94
|
+
*/
|
|
95
|
+
estimateSize(value) {
|
|
96
|
+
try {
|
|
97
|
+
return JSON.stringify(value).length * 2; // Rough estimate (UTF-16)
|
|
98
|
+
}
|
|
99
|
+
catch (_a) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Match key against pattern
|
|
105
|
+
*/
|
|
106
|
+
matchPattern(key, pattern, mode) {
|
|
107
|
+
switch (mode) {
|
|
108
|
+
case 'prefix':
|
|
109
|
+
return key.startsWith(pattern);
|
|
110
|
+
case 'suffix':
|
|
111
|
+
return key.endsWith(pattern);
|
|
112
|
+
case 'contains':
|
|
113
|
+
return key.includes(pattern);
|
|
114
|
+
default:
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.BaseCacheProvider = BaseCacheProvider;
|
|
120
|
+
//# sourceMappingURL=base-cache-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-cache-provider.js","sourceRoot":"","sources":["../../../../../utils-cache-connector/src/providers/base-cache-provider.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAWH,MAAsB,iBAAiB;IAAvC;QACY,UAAK,GAAe;YAC5B,IAAI,EAAE,CAAC;YACP,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,CAAC;YACX,UAAU,EAAE,CAAC;YACb,IAAI,EAAE,CAAC;YACP,SAAS,EAAE,CAAC;YACZ,WAAW,EAAE,CAAC;SACf,CAAC;IA6JJ,CAAC;IA3GC;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,sBAA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