@fjell/cache 4.7.39 → 4.7.41
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/coverage_output.txt +995 -0
- package/dist/Operations.d.ts +99 -16
- package/dist/Operations.d.ts.map +1 -1
- package/dist/Options.d.ts +6 -0
- package/dist/Options.d.ts.map +1 -1
- package/dist/cache/TwoLayerDemo.d.ts +29 -0
- package/dist/cache/TwoLayerDemo.d.ts.map +1 -0
- package/dist/cache/TwoLayerFactory.d.ts +83 -0
- package/dist/cache/TwoLayerFactory.d.ts.map +1 -0
- package/dist/cache/layers/ItemCache.d.ts +41 -0
- package/dist/cache/layers/ItemCache.d.ts.map +1 -0
- package/dist/cache/layers/QueryCache.d.ts +52 -0
- package/dist/cache/layers/QueryCache.d.ts.map +1 -0
- package/dist/cache/layers/TwoLayerCacheMap.d.ts +115 -0
- package/dist/cache/layers/TwoLayerCacheMap.d.ts.map +1 -0
- package/dist/cache/patterns/StaleWhileRevalidateCache.d.ts +101 -0
- package/dist/cache/patterns/StaleWhileRevalidateCache.d.ts.map +1 -0
- package/dist/cache/types/TwoLayerTypes.d.ts +53 -0
- package/dist/cache/types/TwoLayerTypes.d.ts.map +1 -0
- package/dist/cache/warming/CacheWarmer.d.ts +147 -0
- package/dist/cache/warming/CacheWarmer.d.ts.map +1 -0
- package/dist/index.js +951 -425
- package/dist/ttl/TTLCalculator.d.ts +96 -0
- package/dist/ttl/TTLCalculator.d.ts.map +1 -0
- package/dist/ttl/TTLConfig.d.ts +79 -0
- package/dist/ttl/TTLConfig.d.ts.map +1 -0
- package/package.json +7 -7
- package/test_output.txt +965 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,365 @@
|
|
|
1
1
|
// src/Operations.ts
|
|
2
2
|
import {
|
|
3
|
+
createAllFacetWrapper as createAllFacetWrapper2,
|
|
4
|
+
createAllWrapper as createAllWrapper2,
|
|
5
|
+
createCreateWrapper as createCreateWrapper2,
|
|
6
|
+
createGetWrapper as createGetWrapper2,
|
|
7
|
+
createOneWrapper as createOneWrapper2,
|
|
8
|
+
createRemoveWrapper as createRemoveWrapper2,
|
|
9
|
+
createUpdateWrapper as createUpdateWrapper2,
|
|
3
10
|
isOperationComKey as isComKey7,
|
|
4
11
|
isOperationPriKey as isPriKey
|
|
5
12
|
} from "@fjell/core";
|
|
6
13
|
|
|
14
|
+
// src/logger.ts
|
|
15
|
+
import Logging from "@fjell/logging";
|
|
16
|
+
var LibLogger = Logging.getLogger("@fjell/cache");
|
|
17
|
+
var logger_default = LibLogger;
|
|
18
|
+
|
|
19
|
+
// src/CacheMap.ts
|
|
20
|
+
var CacheMap = class {
|
|
21
|
+
types;
|
|
22
|
+
constructor(types) {
|
|
23
|
+
this.types = types;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/cache/layers/TwoLayerCacheMap.ts
|
|
28
|
+
var logger = logger_default.get("TwoLayerCacheMap");
|
|
29
|
+
var TwoLayerCacheMap = class _TwoLayerCacheMap extends CacheMap {
|
|
30
|
+
constructor(underlyingCache, options = {}) {
|
|
31
|
+
super(underlyingCache.types);
|
|
32
|
+
this.underlyingCache = underlyingCache;
|
|
33
|
+
this.options = {
|
|
34
|
+
itemTTL: options.itemTTL || 3600,
|
|
35
|
+
// 1 hour for items
|
|
36
|
+
queryTTL: options.queryTTL || 300,
|
|
37
|
+
// 5 minutes for complete queries
|
|
38
|
+
facetTTL: options.facetTTL || 60,
|
|
39
|
+
// 1 minute for partial queries
|
|
40
|
+
debug: options.debug || false
|
|
41
|
+
};
|
|
42
|
+
if (this.options.debug) {
|
|
43
|
+
logger.info("TwoLayerCacheMap initialized", {
|
|
44
|
+
underlyingType: this.underlyingCache.implementationType,
|
|
45
|
+
itemTTL: this.options.itemTTL,
|
|
46
|
+
queryTTL: this.options.queryTTL,
|
|
47
|
+
facetTTL: this.options.facetTTL
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
options;
|
|
52
|
+
// Query metadata tracking for enhanced TTL and completeness
|
|
53
|
+
queryMetadataMap = /* @__PURE__ */ new Map();
|
|
54
|
+
// ===== PASS-THROUGH METHODS TO UNDERLYING CACHE (ITEM LAYER) =====
|
|
55
|
+
async get(key) {
|
|
56
|
+
return this.underlyingCache.get(key);
|
|
57
|
+
}
|
|
58
|
+
async set(key, value) {
|
|
59
|
+
await this.underlyingCache.set(key, value);
|
|
60
|
+
await this.invalidateQueriesForItem(key);
|
|
61
|
+
}
|
|
62
|
+
async includesKey(key) {
|
|
63
|
+
return this.underlyingCache.includesKey(key);
|
|
64
|
+
}
|
|
65
|
+
async delete(key) {
|
|
66
|
+
await this.underlyingCache.delete(key);
|
|
67
|
+
await this.invalidateQueriesForItem(key);
|
|
68
|
+
}
|
|
69
|
+
async allIn(locations) {
|
|
70
|
+
return this.underlyingCache.allIn(locations);
|
|
71
|
+
}
|
|
72
|
+
async contains(query, locations) {
|
|
73
|
+
return this.underlyingCache.contains(query, locations);
|
|
74
|
+
}
|
|
75
|
+
async queryIn(query, locations) {
|
|
76
|
+
return this.underlyingCache.queryIn(query, locations);
|
|
77
|
+
}
|
|
78
|
+
async clone() {
|
|
79
|
+
const clonedUnderlying = await this.underlyingCache.clone();
|
|
80
|
+
return new _TwoLayerCacheMap(clonedUnderlying, this.options);
|
|
81
|
+
}
|
|
82
|
+
async keys() {
|
|
83
|
+
return this.underlyingCache.keys();
|
|
84
|
+
}
|
|
85
|
+
async values() {
|
|
86
|
+
return this.underlyingCache.values();
|
|
87
|
+
}
|
|
88
|
+
async clear() {
|
|
89
|
+
await this.underlyingCache.clear();
|
|
90
|
+
this.queryMetadataMap.clear();
|
|
91
|
+
}
|
|
92
|
+
// ===== ENHANCED QUERY LAYER METHODS =====
|
|
93
|
+
/**
|
|
94
|
+
* Set a query result with rich metadata for two-layer architecture
|
|
95
|
+
*/
|
|
96
|
+
async setQueryResult(queryHash, itemKeys) {
|
|
97
|
+
await this.underlyingCache.setQueryResult(queryHash, itemKeys);
|
|
98
|
+
const now = /* @__PURE__ */ new Date();
|
|
99
|
+
const isComplete = this.determineQueryCompleteness(queryHash, itemKeys);
|
|
100
|
+
const ttlSeconds = isComplete ? this.options.queryTTL : this.options.facetTTL;
|
|
101
|
+
const metadata = {
|
|
102
|
+
queryType: this.extractQueryType(queryHash),
|
|
103
|
+
isComplete,
|
|
104
|
+
createdAt: now,
|
|
105
|
+
expiresAt: new Date(now.getTime() + ttlSeconds * 1e3),
|
|
106
|
+
filter: this.extractFilter(queryHash),
|
|
107
|
+
params: this.extractParams(queryHash)
|
|
108
|
+
};
|
|
109
|
+
this.queryMetadataMap.set(queryHash, metadata);
|
|
110
|
+
if (this.options.debug) {
|
|
111
|
+
logger.debug("Set query result with metadata", {
|
|
112
|
+
queryHash,
|
|
113
|
+
itemCount: itemKeys.length,
|
|
114
|
+
isComplete,
|
|
115
|
+
ttlSeconds,
|
|
116
|
+
expiresAt: metadata.expiresAt.toISOString()
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get a query result with expiration checking
|
|
122
|
+
*/
|
|
123
|
+
async getQueryResult(queryHash) {
|
|
124
|
+
const metadata = this.queryMetadataMap.get(queryHash);
|
|
125
|
+
if (metadata && metadata.expiresAt < /* @__PURE__ */ new Date()) {
|
|
126
|
+
await this.deleteQueryResult(queryHash);
|
|
127
|
+
if (this.options.debug) {
|
|
128
|
+
logger.debug("Query result expired and removed", { queryHash });
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const result = await this.underlyingCache.getQueryResult(queryHash);
|
|
133
|
+
if (result && this.options.debug) {
|
|
134
|
+
logger.debug("Query result cache hit", {
|
|
135
|
+
queryHash,
|
|
136
|
+
itemCount: result.length,
|
|
137
|
+
isComplete: metadata?.isComplete
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if query result exists and is not expired
|
|
144
|
+
*/
|
|
145
|
+
async hasQueryResult(queryHash) {
|
|
146
|
+
const result = await this.getQueryResult(queryHash);
|
|
147
|
+
return result !== null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Delete a query result and its metadata
|
|
151
|
+
*/
|
|
152
|
+
async deleteQueryResult(queryHash) {
|
|
153
|
+
await this.underlyingCache.deleteQueryResult(queryHash);
|
|
154
|
+
this.queryMetadataMap.delete(queryHash);
|
|
155
|
+
if (this.options.debug) {
|
|
156
|
+
logger.debug("Deleted query result", { queryHash });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// ===== QUERY INVALIDATION (CRITICAL FOR TWO-LAYER ARCHITECTURE) =====
|
|
160
|
+
/**
|
|
161
|
+
* Invalidate queries that are affected by item changes
|
|
162
|
+
*/
|
|
163
|
+
async invalidateQueriesForItem(itemKey) {
|
|
164
|
+
const affectedQueries = await this.findQueriesContainingItem(itemKey);
|
|
165
|
+
for (const queryHash of affectedQueries) {
|
|
166
|
+
await this.deleteQueryResult(queryHash);
|
|
167
|
+
}
|
|
168
|
+
if (this.options.debug && affectedQueries.length > 0) {
|
|
169
|
+
logger.debug("Invalidated queries for item change", {
|
|
170
|
+
itemKey: JSON.stringify(itemKey),
|
|
171
|
+
queriesInvalidated: affectedQueries.length
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Find queries that contain a specific item (requires scanning - can be optimized)
|
|
177
|
+
*/
|
|
178
|
+
async findQueriesContainingItem(itemKey) {
|
|
179
|
+
const affectedQueries = [];
|
|
180
|
+
const itemKeyStr = JSON.stringify(itemKey);
|
|
181
|
+
for (const [queryHash, metadata] of this.queryMetadataMap.entries()) {
|
|
182
|
+
const queryResult = await this.underlyingCache.getQueryResult(queryHash);
|
|
183
|
+
if (queryResult && queryResult.some((key) => JSON.stringify(key) === itemKeyStr)) {
|
|
184
|
+
affectedQueries.push(queryHash);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return affectedQueries;
|
|
188
|
+
}
|
|
189
|
+
// ===== METADATA UTILITY METHODS =====
|
|
190
|
+
/**
|
|
191
|
+
* Determine if a query result is complete or partial based on query hash
|
|
192
|
+
*/
|
|
193
|
+
determineQueryCompleteness(queryHash, itemKeys) {
|
|
194
|
+
if (queryHash.includes("facet:") || queryHash.includes("filter:")) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
if (queryHash.includes("all:") && !queryHash.includes("query:")) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Extract query type from hash for metadata
|
|
204
|
+
*/
|
|
205
|
+
extractQueryType(queryHash) {
|
|
206
|
+
if (queryHash.startsWith("all:")) return "all";
|
|
207
|
+
if (queryHash.startsWith("find:")) return "find";
|
|
208
|
+
if (queryHash.startsWith("one:")) return "one";
|
|
209
|
+
if (queryHash.startsWith("facet:")) return "facet";
|
|
210
|
+
return "unknown";
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Extract filter information from query hash
|
|
214
|
+
*/
|
|
215
|
+
extractFilter(queryHash) {
|
|
216
|
+
const filterMatch = queryHash.match(/filter:([^:]+)/);
|
|
217
|
+
return filterMatch ? filterMatch[1] : void 0;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Extract parameters from query hash
|
|
221
|
+
*/
|
|
222
|
+
extractParams(queryHash) {
|
|
223
|
+
try {
|
|
224
|
+
const paramsMatch = queryHash.match(/params:(.+)$/);
|
|
225
|
+
return paramsMatch ? JSON.parse(decodeURIComponent(paramsMatch[1])) : void 0;
|
|
226
|
+
} catch (error) {
|
|
227
|
+
return void 0;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// ===== METADATA PROVIDER METHODS (DELEGATE TO UNDERLYING) =====
|
|
231
|
+
async getMetadata(key) {
|
|
232
|
+
if ("getMetadata" in this.underlyingCache) {
|
|
233
|
+
return this.underlyingCache.getMetadata(key);
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
async setMetadata(key, metadata) {
|
|
238
|
+
if ("setMetadata" in this.underlyingCache) {
|
|
239
|
+
await this.underlyingCache.setMetadata(key, metadata);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async deleteMetadata(key) {
|
|
243
|
+
if ("deleteMetadata" in this.underlyingCache) {
|
|
244
|
+
await this.underlyingCache.deleteMetadata(key);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async getAllMetadata() {
|
|
248
|
+
if ("getAllMetadata" in this.underlyingCache) {
|
|
249
|
+
return this.underlyingCache.getAllMetadata();
|
|
250
|
+
}
|
|
251
|
+
return /* @__PURE__ */ new Map();
|
|
252
|
+
}
|
|
253
|
+
async clearMetadata() {
|
|
254
|
+
if ("clearMetadata" in this.underlyingCache) {
|
|
255
|
+
await this.underlyingCache.clearMetadata();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async getCurrentSize() {
|
|
259
|
+
if ("getCurrentSize" in this.underlyingCache) {
|
|
260
|
+
return this.underlyingCache.getCurrentSize();
|
|
261
|
+
}
|
|
262
|
+
const keys = await this.keys();
|
|
263
|
+
return { itemCount: keys.length, sizeBytes: 0 };
|
|
264
|
+
}
|
|
265
|
+
async getSizeLimits() {
|
|
266
|
+
if ("getSizeLimits" in this.underlyingCache) {
|
|
267
|
+
return this.underlyingCache.getSizeLimits();
|
|
268
|
+
}
|
|
269
|
+
return { maxItems: null, maxSizeBytes: null };
|
|
270
|
+
}
|
|
271
|
+
// ===== TWO-LAYER SPECIFIC METHODS =====
|
|
272
|
+
/**
|
|
273
|
+
* Get statistics about the two-layer cache
|
|
274
|
+
*/
|
|
275
|
+
getTwoLayerStats() {
|
|
276
|
+
const now = /* @__PURE__ */ new Date();
|
|
277
|
+
let expiredQueries = 0;
|
|
278
|
+
let validQueries = 0;
|
|
279
|
+
let completeQueries = 0;
|
|
280
|
+
let partialQueries = 0;
|
|
281
|
+
for (const [queryHash, metadata] of this.queryMetadataMap.entries()) {
|
|
282
|
+
if (metadata.expiresAt < now) {
|
|
283
|
+
expiredQueries++;
|
|
284
|
+
} else {
|
|
285
|
+
validQueries++;
|
|
286
|
+
if (metadata.isComplete) {
|
|
287
|
+
completeQueries++;
|
|
288
|
+
} else {
|
|
289
|
+
partialQueries++;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
queryMetadata: {
|
|
295
|
+
total: this.queryMetadataMap.size,
|
|
296
|
+
valid: validQueries,
|
|
297
|
+
expired: expiredQueries,
|
|
298
|
+
complete: completeQueries,
|
|
299
|
+
partial: partialQueries
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Clean up expired queries
|
|
305
|
+
*/
|
|
306
|
+
async cleanup() {
|
|
307
|
+
const now = /* @__PURE__ */ new Date();
|
|
308
|
+
const expiredQueries = [];
|
|
309
|
+
for (const [queryHash, metadata] of this.queryMetadataMap.entries()) {
|
|
310
|
+
if (metadata.expiresAt < now) {
|
|
311
|
+
expiredQueries.push(queryHash);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const queryHash of expiredQueries) {
|
|
315
|
+
await this.deleteQueryResult(queryHash);
|
|
316
|
+
}
|
|
317
|
+
if (this.options.debug && expiredQueries.length > 0) {
|
|
318
|
+
logger.debug("Cleaned up expired queries", { count: expiredQueries.length });
|
|
319
|
+
}
|
|
320
|
+
return expiredQueries.length;
|
|
321
|
+
}
|
|
322
|
+
// ===== PROPERTIES =====
|
|
323
|
+
get implementationType() {
|
|
324
|
+
return `two-layer/${this.underlyingCache.implementationType}`;
|
|
325
|
+
}
|
|
326
|
+
// Note: Removed types getter to avoid override conflict with base class
|
|
327
|
+
// The types are accessible through super.types
|
|
328
|
+
// ===== MISSING ABSTRACT METHODS FROM CacheMap =====
|
|
329
|
+
async invalidateItemKeys(keys) {
|
|
330
|
+
if ("invalidateItemKeys" in this.underlyingCache && typeof this.underlyingCache.invalidateItemKeys === "function") {
|
|
331
|
+
await this.underlyingCache.invalidateItemKeys(keys);
|
|
332
|
+
}
|
|
333
|
+
for (const key of keys) {
|
|
334
|
+
await this.invalidateQueriesForItem(key);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async invalidateLocation(locations) {
|
|
338
|
+
if ("invalidateLocation" in this.underlyingCache && typeof this.underlyingCache.invalidateLocation === "function") {
|
|
339
|
+
await this.underlyingCache.invalidateLocation(locations);
|
|
340
|
+
}
|
|
341
|
+
this.queryMetadataMap.clear();
|
|
342
|
+
}
|
|
343
|
+
async clearQueryResults() {
|
|
344
|
+
if ("clearQueryResults" in this.underlyingCache && typeof this.underlyingCache.clearQueryResults === "function") {
|
|
345
|
+
await this.underlyingCache.clearQueryResults();
|
|
346
|
+
}
|
|
347
|
+
this.queryMetadataMap.clear();
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Check if two-layer mode is enabled
|
|
351
|
+
*/
|
|
352
|
+
get isTwoLayerEnabled() {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get the underlying cache implementation
|
|
357
|
+
*/
|
|
358
|
+
get underlying() {
|
|
359
|
+
return this.underlyingCache;
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
7
363
|
// src/CacheContext.ts
|
|
8
364
|
var createCacheContext = (api, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry, coordinate) => {
|
|
9
365
|
return {
|
|
@@ -315,16 +671,11 @@ var CacheEventFactory = class {
|
|
|
315
671
|
}
|
|
316
672
|
};
|
|
317
673
|
|
|
318
|
-
// src/logger.ts
|
|
319
|
-
import Logging from "@fjell/logging";
|
|
320
|
-
var LibLogger = Logging.getLogger("@fjell/cache");
|
|
321
|
-
var logger_default = LibLogger;
|
|
322
|
-
|
|
323
674
|
// src/ops/all.ts
|
|
324
|
-
var
|
|
675
|
+
var logger2 = logger_default.get("all");
|
|
325
676
|
var all = async (query = {}, locations = [], context) => {
|
|
326
677
|
const { api, cacheMap, pkType, ttlManager, coordinate } = context;
|
|
327
|
-
|
|
678
|
+
logger2.default("all", { query, locations });
|
|
328
679
|
const wrappedAll = createAllWrapper(
|
|
329
680
|
coordinate,
|
|
330
681
|
async (q, locs) => {
|
|
@@ -337,21 +688,21 @@ var all = async (query = {}, locations = [], context) => {
|
|
|
337
688
|
async function executeAllLogic(query, locations, context) {
|
|
338
689
|
const { api, cacheMap, pkType, ttlManager } = context;
|
|
339
690
|
if (context.options?.bypassCache) {
|
|
340
|
-
|
|
691
|
+
logger2.debug("Cache bypass enabled, fetching directly from API", { query, locations });
|
|
341
692
|
try {
|
|
342
693
|
const ret2 = await api.all(query, locations);
|
|
343
|
-
|
|
694
|
+
logger2.debug("API response received (not cached due to bypass)", { query, locations, itemCount: ret2.length });
|
|
344
695
|
return ret2;
|
|
345
696
|
} catch (error) {
|
|
346
|
-
|
|
697
|
+
logger2.error("API request failed", { query, locations, error });
|
|
347
698
|
throw error;
|
|
348
699
|
}
|
|
349
700
|
}
|
|
350
701
|
const queryHash = createQueryHash(pkType, query, locations);
|
|
351
|
-
|
|
702
|
+
logger2.debug("Generated query hash for all", { queryHash });
|
|
352
703
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
353
704
|
if (cachedItemKeys) {
|
|
354
|
-
|
|
705
|
+
logger2.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
355
706
|
const cachedItems = [];
|
|
356
707
|
let allItemsAvailable = true;
|
|
357
708
|
for (const itemKey of cachedItemKeys) {
|
|
@@ -366,21 +717,21 @@ async function executeAllLogic(query, locations, context) {
|
|
|
366
717
|
if (allItemsAvailable) {
|
|
367
718
|
return cachedItems;
|
|
368
719
|
} else {
|
|
369
|
-
|
|
720
|
+
logger2.debug("Some cached items missing, invalidating query cache");
|
|
370
721
|
cacheMap.deleteQueryResult(queryHash);
|
|
371
722
|
}
|
|
372
723
|
}
|
|
373
724
|
try {
|
|
374
725
|
const directCachedItems = await cacheMap.queryIn(query, locations);
|
|
375
726
|
if (directCachedItems && directCachedItems.length > 0) {
|
|
376
|
-
|
|
727
|
+
logger2.debug("Found items directly in cache, skipping API call", { itemCount: directCachedItems.length });
|
|
377
728
|
const itemKeys = directCachedItems.map((item) => item.key);
|
|
378
729
|
await cacheMap.setQueryResult(queryHash, itemKeys);
|
|
379
|
-
|
|
730
|
+
logger2.debug("Cached query result from direct cache hit", { queryHash, itemKeyCount: itemKeys.length });
|
|
380
731
|
return directCachedItems;
|
|
381
732
|
}
|
|
382
733
|
} catch (error) {
|
|
383
|
-
|
|
734
|
+
logger2.debug("Error querying cache directly, proceeding to API", { error });
|
|
384
735
|
}
|
|
385
736
|
let ret = [];
|
|
386
737
|
try {
|
|
@@ -397,13 +748,13 @@ async function executeAllLogic(query, locations, context) {
|
|
|
397
748
|
}
|
|
398
749
|
const itemKeys = ret.map((item) => item.key);
|
|
399
750
|
cacheMap.setQueryResult(queryHash, itemKeys);
|
|
400
|
-
|
|
751
|
+
logger2.debug("Cached query result", { queryHash, itemKeyCount: itemKeys.length });
|
|
401
752
|
const event = CacheEventFactory.createQueryEvent(query, locations, ret);
|
|
402
753
|
context.eventEmitter.emit(event);
|
|
403
754
|
} catch (e) {
|
|
404
755
|
if (e instanceof NotFoundError) {
|
|
405
756
|
cacheMap.setQueryResult(queryHash, []);
|
|
406
|
-
|
|
757
|
+
logger2.debug("Cached empty query result for not found", { queryHash });
|
|
407
758
|
} else {
|
|
408
759
|
throw e;
|
|
409
760
|
}
|
|
@@ -578,10 +929,10 @@ function validateSizeConfig(config) {
|
|
|
578
929
|
}
|
|
579
930
|
|
|
580
931
|
// src/ops/one.ts
|
|
581
|
-
var
|
|
932
|
+
var logger3 = logger_default.get("one");
|
|
582
933
|
var one = async (query = {}, locations = [], context) => {
|
|
583
934
|
const { api, cacheMap, pkType, ttlManager, coordinate } = context;
|
|
584
|
-
|
|
935
|
+
logger3.default("one", { query, locations });
|
|
585
936
|
const wrappedOne = createOneWrapper(
|
|
586
937
|
coordinate,
|
|
587
938
|
async (q, locs) => {
|
|
@@ -594,26 +945,26 @@ var one = async (query = {}, locations = [], context) => {
|
|
|
594
945
|
async function executeOneLogic(query, locations, context) {
|
|
595
946
|
const { api, cacheMap, pkType, ttlManager } = context;
|
|
596
947
|
if (context.options?.bypassCache) {
|
|
597
|
-
|
|
948
|
+
logger3.debug("Cache bypass enabled, fetching directly from API", { query, locations });
|
|
598
949
|
try {
|
|
599
950
|
const retItem2 = await api.one(query, locations);
|
|
600
951
|
if (retItem2) {
|
|
601
|
-
|
|
952
|
+
logger3.debug("API response received (not cached due to bypass)", { query, locations });
|
|
602
953
|
return retItem2;
|
|
603
954
|
} else {
|
|
604
|
-
|
|
955
|
+
logger3.debug("API returned null", { query, locations });
|
|
605
956
|
return null;
|
|
606
957
|
}
|
|
607
958
|
} catch (error) {
|
|
608
|
-
|
|
959
|
+
logger3.error("API request failed", { query, locations, error });
|
|
609
960
|
throw error;
|
|
610
961
|
}
|
|
611
962
|
}
|
|
612
963
|
const queryHash = createQueryHash(pkType, query, locations);
|
|
613
|
-
|
|
964
|
+
logger3.debug("Generated query hash for one", { queryHash });
|
|
614
965
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
615
966
|
if (cachedItemKeys) {
|
|
616
|
-
|
|
967
|
+
logger3.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
617
968
|
if (cachedItemKeys.length === 0) {
|
|
618
969
|
return null;
|
|
619
970
|
}
|
|
@@ -621,21 +972,21 @@ async function executeOneLogic(query, locations, context) {
|
|
|
621
972
|
if (item) {
|
|
622
973
|
return item;
|
|
623
974
|
} else {
|
|
624
|
-
|
|
975
|
+
logger3.debug("Cached item missing, invalidating query cache");
|
|
625
976
|
cacheMap.deleteQueryResult(queryHash);
|
|
626
977
|
}
|
|
627
978
|
}
|
|
628
979
|
try {
|
|
629
980
|
const directCachedItems = await cacheMap.queryIn(query, locations);
|
|
630
981
|
if (directCachedItems && directCachedItems.length > 0) {
|
|
631
|
-
|
|
982
|
+
logger3.debug("Found item directly in cache, skipping API call");
|
|
632
983
|
const foundItem = directCachedItems[0];
|
|
633
984
|
await cacheMap.setQueryResult(queryHash, [foundItem.key]);
|
|
634
|
-
|
|
985
|
+
logger3.debug("Cached query result from direct cache hit", { queryHash, itemKey: foundItem.key });
|
|
635
986
|
return foundItem;
|
|
636
987
|
}
|
|
637
988
|
} catch (error) {
|
|
638
|
-
|
|
989
|
+
logger3.debug("Error querying cache directly, proceeding to API", { error });
|
|
639
990
|
}
|
|
640
991
|
let retItem = null;
|
|
641
992
|
try {
|
|
@@ -662,15 +1013,15 @@ async function executeOneLogic(query, locations, context) {
|
|
|
662
1013
|
await cacheMap.delete(parsedKey);
|
|
663
1014
|
}
|
|
664
1015
|
await cacheMap.setQueryResult(queryHash, [retItem.key]);
|
|
665
|
-
|
|
1016
|
+
logger3.debug("Cached query result", { queryHash, itemKey: retItem.key });
|
|
666
1017
|
} else {
|
|
667
1018
|
await cacheMap.setQueryResult(queryHash, []);
|
|
668
|
-
|
|
1019
|
+
logger3.debug("Cached empty query result", { queryHash });
|
|
669
1020
|
}
|
|
670
1021
|
} catch (e) {
|
|
671
1022
|
if (e instanceof NotFoundError2) {
|
|
672
1023
|
cacheMap.setQueryResult(queryHash, []);
|
|
673
|
-
|
|
1024
|
+
logger3.debug("Cached empty query result for not found", { queryHash });
|
|
674
1025
|
} else {
|
|
675
1026
|
throw e;
|
|
676
1027
|
}
|
|
@@ -682,10 +1033,10 @@ async function executeOneLogic(query, locations, context) {
|
|
|
682
1033
|
import {
|
|
683
1034
|
createCreateWrapper
|
|
684
1035
|
} from "@fjell/core";
|
|
685
|
-
var
|
|
1036
|
+
var logger4 = logger_default.get("create");
|
|
686
1037
|
var create = async (v, locations = [], context) => {
|
|
687
1038
|
const { coordinate } = context;
|
|
688
|
-
|
|
1039
|
+
logger4.default("create", { v, locations });
|
|
689
1040
|
const wrappedCreate = createCreateWrapper(
|
|
690
1041
|
coordinate,
|
|
691
1042
|
async (item, createOptions2) => {
|
|
@@ -725,7 +1076,7 @@ import {
|
|
|
725
1076
|
createGetWrapper,
|
|
726
1077
|
isValidItemKey
|
|
727
1078
|
} from "@fjell/core";
|
|
728
|
-
var
|
|
1079
|
+
var logger5 = logger_default.get("get");
|
|
729
1080
|
var inFlightRequests = /* @__PURE__ */ new Map();
|
|
730
1081
|
var CLEANUP_TIMEOUT = 5 * 60 * 1e3;
|
|
731
1082
|
var cleanupStaleRequests = () => {
|
|
@@ -737,7 +1088,7 @@ var cleanupStaleRequests = () => {
|
|
|
737
1088
|
}
|
|
738
1089
|
});
|
|
739
1090
|
keysToDelete.forEach((key) => {
|
|
740
|
-
|
|
1091
|
+
logger5.debug("Cleaning up stale in-flight request", { key });
|
|
741
1092
|
inFlightRequests.delete(key);
|
|
742
1093
|
});
|
|
743
1094
|
};
|
|
@@ -745,7 +1096,7 @@ var cleanupInterval = setInterval(cleanupStaleRequests, 60 * 1e3);
|
|
|
745
1096
|
var keyToString = createNormalizedHashFunction();
|
|
746
1097
|
var get = async (key, context) => {
|
|
747
1098
|
const { api, cacheMap, pkType, ttlManager, statsManager, coordinate } = context;
|
|
748
|
-
|
|
1099
|
+
logger5.default("get", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
749
1100
|
const wrappedGet = createGetWrapper(
|
|
750
1101
|
coordinate,
|
|
751
1102
|
async (k) => {
|
|
@@ -759,23 +1110,23 @@ async function executeGetLogic(key, context) {
|
|
|
759
1110
|
const { api, cacheMap, pkType, ttlManager, statsManager } = context;
|
|
760
1111
|
statsManager.incrementRequests();
|
|
761
1112
|
if (!isValidItemKey(key)) {
|
|
762
|
-
|
|
1113
|
+
logger5.error("Key for Get is not a valid ItemKey: %j", key);
|
|
763
1114
|
throw new Error("Key for Get is not a valid ItemKey");
|
|
764
1115
|
}
|
|
765
1116
|
if (context.options?.bypassCache) {
|
|
766
|
-
|
|
1117
|
+
logger5.debug("Cache bypass enabled, fetching directly from API", { key });
|
|
767
1118
|
statsManager.incrementMisses();
|
|
768
1119
|
try {
|
|
769
1120
|
const ret2 = await api.get(key);
|
|
770
1121
|
if (ret2) {
|
|
771
|
-
|
|
1122
|
+
logger5.debug("API response received (not cached due to bypass)", { key });
|
|
772
1123
|
return ret2;
|
|
773
1124
|
} else {
|
|
774
|
-
|
|
1125
|
+
logger5.debug("API returned null", { key });
|
|
775
1126
|
return null;
|
|
776
1127
|
}
|
|
777
1128
|
} catch (error) {
|
|
778
|
-
|
|
1129
|
+
logger5.error("API request failed", { key, error });
|
|
779
1130
|
throw error;
|
|
780
1131
|
}
|
|
781
1132
|
}
|
|
@@ -785,22 +1136,22 @@ async function executeGetLogic(key, context) {
|
|
|
785
1136
|
if (cachedItem) {
|
|
786
1137
|
const isValid = await ttlManager.validateItem(keyStr2, cacheMap);
|
|
787
1138
|
if (isValid) {
|
|
788
|
-
|
|
1139
|
+
logger5.debug("Cache hit with valid TTL", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
789
1140
|
statsManager.incrementHits();
|
|
790
1141
|
return cachedItem;
|
|
791
1142
|
} else {
|
|
792
|
-
|
|
1143
|
+
logger5.debug("Cache item expired, removing", { key });
|
|
793
1144
|
cacheMap.delete(key);
|
|
794
1145
|
statsManager.incrementMisses();
|
|
795
1146
|
}
|
|
796
1147
|
} else {
|
|
797
1148
|
statsManager.incrementMisses();
|
|
798
1149
|
}
|
|
799
|
-
|
|
1150
|
+
logger5.debug("Cache miss or expired", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
800
1151
|
} else {
|
|
801
1152
|
const cachedItem = await cacheMap.get(key);
|
|
802
1153
|
if (cachedItem) {
|
|
803
|
-
|
|
1154
|
+
logger5.debug("Cache hit (TTL disabled)", { key });
|
|
804
1155
|
statsManager.incrementHits();
|
|
805
1156
|
return cachedItem;
|
|
806
1157
|
} else {
|
|
@@ -825,7 +1176,7 @@ async function executeGetLogic(key, context) {
|
|
|
825
1176
|
}
|
|
826
1177
|
}
|
|
827
1178
|
} else {
|
|
828
|
-
|
|
1179
|
+
logger5.debug("Using in-flight request for key", { key });
|
|
829
1180
|
apiRequest = requestEntry.promise;
|
|
830
1181
|
}
|
|
831
1182
|
ret = await apiRequest;
|
|
@@ -855,7 +1206,7 @@ async function executeGetLogic(key, context) {
|
|
|
855
1206
|
}
|
|
856
1207
|
} catch (e) {
|
|
857
1208
|
inFlightRequests.delete(keyStr);
|
|
858
|
-
|
|
1209
|
+
logger5.error("Error getting item for key", { key, message: e.message, stack: e.stack });
|
|
859
1210
|
throw e;
|
|
860
1211
|
}
|
|
861
1212
|
return ret || null;
|
|
@@ -865,30 +1216,30 @@ async function executeGetLogic(key, context) {
|
|
|
865
1216
|
import {
|
|
866
1217
|
isValidItemKey as isValidItemKey2
|
|
867
1218
|
} from "@fjell/core";
|
|
868
|
-
var
|
|
1219
|
+
var logger6 = logger_default.get("retrieve");
|
|
869
1220
|
var retrieve = async (key, context) => {
|
|
870
1221
|
const { cacheMap, pkType, statsManager } = context;
|
|
871
|
-
|
|
1222
|
+
logger6.default("retrieve", { key });
|
|
872
1223
|
statsManager.incrementRequests();
|
|
873
1224
|
if (!isValidItemKey2(key)) {
|
|
874
|
-
|
|
1225
|
+
logger6.error("Key for Retrieve is not a valid ItemKey: %j", key);
|
|
875
1226
|
throw new Error("Key for Retrieve is not a valid ItemKey");
|
|
876
1227
|
}
|
|
877
1228
|
if (context.options?.bypassCache) {
|
|
878
|
-
|
|
1229
|
+
logger6.debug("Cache bypass enabled, fetching directly from API", { key });
|
|
879
1230
|
statsManager.incrementMisses();
|
|
880
1231
|
try {
|
|
881
1232
|
const { api } = context;
|
|
882
1233
|
const retrieved2 = await api.get(key);
|
|
883
1234
|
if (retrieved2) {
|
|
884
|
-
|
|
1235
|
+
logger6.debug("API response received (not cached due to bypass)", { key });
|
|
885
1236
|
return [null, retrieved2];
|
|
886
1237
|
} else {
|
|
887
|
-
|
|
1238
|
+
logger6.debug("API returned null", { key });
|
|
888
1239
|
return [null, null];
|
|
889
1240
|
}
|
|
890
1241
|
} catch (error) {
|
|
891
|
-
|
|
1242
|
+
logger6.error("API request failed", { key, error });
|
|
892
1243
|
throw error;
|
|
893
1244
|
}
|
|
894
1245
|
}
|
|
@@ -896,12 +1247,12 @@ var retrieve = async (key, context) => {
|
|
|
896
1247
|
let retrieved;
|
|
897
1248
|
let contextToReturn;
|
|
898
1249
|
if (containsItemKey) {
|
|
899
|
-
|
|
1250
|
+
logger6.default("Looking for Object in Cache", key);
|
|
900
1251
|
retrieved = await cacheMap.get(key);
|
|
901
1252
|
contextToReturn = null;
|
|
902
1253
|
statsManager.incrementHits();
|
|
903
1254
|
} else {
|
|
904
|
-
|
|
1255
|
+
logger6.default("Object Not Found in Cache, Retrieving from Server API", { key });
|
|
905
1256
|
statsManager.incrementMisses();
|
|
906
1257
|
[contextToReturn, retrieved] = await get(key, context);
|
|
907
1258
|
}
|
|
@@ -917,10 +1268,10 @@ import {
|
|
|
917
1268
|
createRemoveWrapper,
|
|
918
1269
|
isValidItemKey as isValidItemKey3
|
|
919
1270
|
} from "@fjell/core";
|
|
920
|
-
var
|
|
1271
|
+
var logger7 = logger_default.get("remove");
|
|
921
1272
|
var remove = async (key, context) => {
|
|
922
1273
|
const { coordinate } = context;
|
|
923
|
-
|
|
1274
|
+
logger7.default("remove", { key });
|
|
924
1275
|
const wrappedRemove = createRemoveWrapper(
|
|
925
1276
|
coordinate,
|
|
926
1277
|
async (k) => {
|
|
@@ -933,7 +1284,7 @@ var remove = async (key, context) => {
|
|
|
933
1284
|
async function executeRemoveLogic(key, context) {
|
|
934
1285
|
const { api, cacheMap } = context;
|
|
935
1286
|
if (!isValidItemKey3(key)) {
|
|
936
|
-
|
|
1287
|
+
logger7.error("Key for Remove is not a valid ItemKey: %j", key);
|
|
937
1288
|
throw new Error("Key for Remove is not a valid ItemKey");
|
|
938
1289
|
}
|
|
939
1290
|
try {
|
|
@@ -951,9 +1302,9 @@ async function executeRemoveLogic(key, context) {
|
|
|
951
1302
|
{ source: "operation", context: { operation: "remove" } }
|
|
952
1303
|
);
|
|
953
1304
|
context.eventEmitter.emit(queryInvalidatedEvent);
|
|
954
|
-
|
|
1305
|
+
logger7.debug("Successfully removed item from API and cache", { key });
|
|
955
1306
|
} catch (e) {
|
|
956
|
-
|
|
1307
|
+
logger7.error("Error deleting item", { error: e });
|
|
957
1308
|
throw e;
|
|
958
1309
|
}
|
|
959
1310
|
}
|
|
@@ -963,10 +1314,10 @@ import {
|
|
|
963
1314
|
createUpdateWrapper,
|
|
964
1315
|
isValidItemKey as isValidItemKey4
|
|
965
1316
|
} from "@fjell/core";
|
|
966
|
-
var
|
|
1317
|
+
var logger8 = logger_default.get("update");
|
|
967
1318
|
var update = async (key, v, context) => {
|
|
968
1319
|
const { coordinate } = context;
|
|
969
|
-
|
|
1320
|
+
logger8.default("update", { key, v });
|
|
970
1321
|
const wrappedUpdate = createUpdateWrapper(
|
|
971
1322
|
coordinate,
|
|
972
1323
|
async (k, item) => {
|
|
@@ -979,16 +1330,16 @@ var update = async (key, v, context) => {
|
|
|
979
1330
|
async function executeUpdateLogic(key, v, context) {
|
|
980
1331
|
const { api, cacheMap, pkType } = context;
|
|
981
1332
|
if (!isValidItemKey4(key)) {
|
|
982
|
-
|
|
1333
|
+
logger8.error("Key for Update is not a valid ItemKey: %j", key);
|
|
983
1334
|
throw new Error("Key for Update is not a valid ItemKey");
|
|
984
1335
|
}
|
|
985
|
-
|
|
1336
|
+
logger8.debug("Invalidating item key before update", { key });
|
|
986
1337
|
cacheMap.invalidateItemKeys([key]);
|
|
987
1338
|
await cacheMap.clearQueryResults();
|
|
988
1339
|
try {
|
|
989
1340
|
const previousItem = await cacheMap.get(key);
|
|
990
1341
|
const updated = await api.update(key, v);
|
|
991
|
-
|
|
1342
|
+
logger8.debug("Caching update result", { updatedKey: updated.key });
|
|
992
1343
|
await cacheMap.set(updated.key, updated);
|
|
993
1344
|
const cachedItem = await cacheMap.get(updated.key);
|
|
994
1345
|
const keyStr = JSON.stringify(updated.key);
|
|
@@ -1021,7 +1372,7 @@ async function executeUpdateLogic(key, v, context) {
|
|
|
1021
1372
|
context.eventEmitter.emit(queryInvalidatedEvent);
|
|
1022
1373
|
return updated;
|
|
1023
1374
|
} catch (e) {
|
|
1024
|
-
|
|
1375
|
+
logger8.error("Error updating item", { error: e });
|
|
1025
1376
|
throw e;
|
|
1026
1377
|
}
|
|
1027
1378
|
}
|
|
@@ -1034,7 +1385,7 @@ import {
|
|
|
1034
1385
|
|
|
1035
1386
|
// src/utils/cacheInvalidation.ts
|
|
1036
1387
|
import { toKeyTypeArray } from "@fjell/core";
|
|
1037
|
-
var
|
|
1388
|
+
var logger9 = logger_default.get("cache", "utils", "cacheInvalidation");
|
|
1038
1389
|
var extractKeysAndKeyTypesFromActionResult = (affectedItems) => {
|
|
1039
1390
|
const keys = [];
|
|
1040
1391
|
const keyTypeArrays = [];
|
|
@@ -1051,7 +1402,7 @@ var extractKeysAndKeyTypesFromActionResult = (affectedItems) => {
|
|
|
1051
1402
|
return { keys, keyTypeArrays };
|
|
1052
1403
|
};
|
|
1053
1404
|
var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) => {
|
|
1054
|
-
|
|
1405
|
+
logger9.debug("Invalidating caches by keys and key types", {
|
|
1055
1406
|
keysCount: keys.length,
|
|
1056
1407
|
keyTypeArrays
|
|
1057
1408
|
});
|
|
@@ -1069,22 +1420,22 @@ var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) =>
|
|
|
1069
1420
|
try {
|
|
1070
1421
|
const cacheInstance = registry.get(keyTypes);
|
|
1071
1422
|
if (cacheInstance && isCache(cacheInstance)) {
|
|
1072
|
-
|
|
1423
|
+
logger9.debug("Found cache instance for targeted invalidation", {
|
|
1073
1424
|
keyTypes,
|
|
1074
1425
|
cacheType: cacheInstance.coordinate.kta,
|
|
1075
1426
|
keysToInvalidate: cacheKeys.length
|
|
1076
1427
|
});
|
|
1077
1428
|
await cacheInstance.cacheMap.invalidateItemKeys(cacheKeys);
|
|
1078
1429
|
await cacheInstance.cacheMap.clearQueryResults();
|
|
1079
|
-
|
|
1430
|
+
logger9.debug("Successfully invalidated specific items in cache", {
|
|
1080
1431
|
keyTypes,
|
|
1081
1432
|
invalidatedCount: cacheKeys.length
|
|
1082
1433
|
});
|
|
1083
1434
|
} else {
|
|
1084
|
-
|
|
1435
|
+
logger9.debug("No cache instance found for key types", { keyTypes });
|
|
1085
1436
|
}
|
|
1086
1437
|
} catch (error) {
|
|
1087
|
-
|
|
1438
|
+
logger9.warning("Failed to invalidate cache for key types", {
|
|
1088
1439
|
keyTypes,
|
|
1089
1440
|
error: error instanceof Error ? error.message : String(error)
|
|
1090
1441
|
});
|
|
@@ -1094,12 +1445,12 @@ var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) =>
|
|
|
1094
1445
|
try {
|
|
1095
1446
|
const cacheInstance = registry.get(keyTypes);
|
|
1096
1447
|
if (cacheInstance && isCache(cacheInstance)) {
|
|
1097
|
-
|
|
1448
|
+
logger9.debug("Handling location-based invalidation", { keyTypes });
|
|
1098
1449
|
await cacheInstance.cacheMap.clearQueryResults();
|
|
1099
|
-
|
|
1450
|
+
logger9.debug("Successfully cleared query results for location", { keyTypes });
|
|
1100
1451
|
}
|
|
1101
1452
|
} catch (error) {
|
|
1102
|
-
|
|
1453
|
+
logger9.warning("Failed to handle location-based invalidation", {
|
|
1103
1454
|
keyTypes,
|
|
1104
1455
|
error: error instanceof Error ? error.message : String(error)
|
|
1105
1456
|
});
|
|
@@ -1110,7 +1461,7 @@ function isCache(instance) {
|
|
|
1110
1461
|
return instance !== null && typeof instance === "object" && "operations" in instance && "cacheMap" in instance && typeof instance.cacheMap.invalidateItemKeys === "function";
|
|
1111
1462
|
}
|
|
1112
1463
|
var handleActionCacheInvalidation = async (registry, affectedItems) => {
|
|
1113
|
-
|
|
1464
|
+
logger9.debug("Handling action cache invalidation", {
|
|
1114
1465
|
affectedItemsCount: affectedItems.length
|
|
1115
1466
|
});
|
|
1116
1467
|
const { keys, keyTypeArrays } = extractKeysAndKeyTypesFromActionResult(affectedItems);
|
|
@@ -1118,10 +1469,10 @@ var handleActionCacheInvalidation = async (registry, affectedItems) => {
|
|
|
1118
1469
|
};
|
|
1119
1470
|
|
|
1120
1471
|
// src/ops/action.ts
|
|
1121
|
-
var
|
|
1472
|
+
var logger10 = logger_default.get("action");
|
|
1122
1473
|
var action = async (key, action2, body = {}, context) => {
|
|
1123
1474
|
const { coordinate } = context;
|
|
1124
|
-
|
|
1475
|
+
logger10.default("action", { key, action: action2, body });
|
|
1125
1476
|
const wrappedAction = createActionWrapper(
|
|
1126
1477
|
coordinate,
|
|
1127
1478
|
async (k, a, b) => {
|
|
@@ -1134,28 +1485,28 @@ var action = async (key, action2, body = {}, context) => {
|
|
|
1134
1485
|
async function executeActionLogic(key, action2, body, context) {
|
|
1135
1486
|
const { api, cacheMap, pkType, registry } = context;
|
|
1136
1487
|
if (!isValidItemKey5(key)) {
|
|
1137
|
-
|
|
1488
|
+
logger10.error("Key for Action is not a valid ItemKey: %j", key);
|
|
1138
1489
|
throw new Error("Key for Action is not a valid ItemKey");
|
|
1139
1490
|
}
|
|
1140
|
-
|
|
1491
|
+
logger10.debug("Invalidating item key before action", { key });
|
|
1141
1492
|
cacheMap.invalidateItemKeys([key]);
|
|
1142
1493
|
const result = await api.action(key, action2, body);
|
|
1143
1494
|
const updated = result[0];
|
|
1144
1495
|
const affectedItems = result[1];
|
|
1145
1496
|
if (affectedItems && affectedItems.length > 0) {
|
|
1146
|
-
|
|
1497
|
+
logger10.debug("Handling cache invalidation for affected items", {
|
|
1147
1498
|
affectedItemsCount: affectedItems.length
|
|
1148
1499
|
});
|
|
1149
1500
|
try {
|
|
1150
1501
|
await handleActionCacheInvalidation(registry, affectedItems);
|
|
1151
1502
|
} catch (error) {
|
|
1152
|
-
|
|
1503
|
+
logger10.warning("Failed to handle cache invalidation for affected items", {
|
|
1153
1504
|
error: error instanceof Error ? error.message : String(error),
|
|
1154
1505
|
affectedItems
|
|
1155
1506
|
});
|
|
1156
1507
|
}
|
|
1157
1508
|
}
|
|
1158
|
-
|
|
1509
|
+
logger10.debug("Caching action result", { updatedKey: updated.key });
|
|
1159
1510
|
cacheMap.set(updated.key, updated);
|
|
1160
1511
|
const keyStr = JSON.stringify(updated.key);
|
|
1161
1512
|
context.ttlManager.onItemAdded(keyStr, cacheMap);
|
|
@@ -1165,19 +1516,19 @@ async function executeActionLogic(key, action2, body, context) {
|
|
|
1165
1516
|
const parsedKey = JSON.parse(evictedKey);
|
|
1166
1517
|
await cacheMap.delete(parsedKey);
|
|
1167
1518
|
} catch (error) {
|
|
1168
|
-
|
|
1519
|
+
logger10.error("Failed to parse evicted key during deletion", {
|
|
1169
1520
|
evictedKey,
|
|
1170
1521
|
error: error instanceof Error ? error.message : String(error)
|
|
1171
1522
|
});
|
|
1172
1523
|
}
|
|
1173
1524
|
}
|
|
1174
|
-
|
|
1525
|
+
logger10.debug("Emitting itemUpdated event after action", {
|
|
1175
1526
|
key: updated.key,
|
|
1176
1527
|
action: action2
|
|
1177
1528
|
});
|
|
1178
1529
|
const itemEvent = CacheEventFactory.itemUpdated(updated.key, updated, null, "api");
|
|
1179
1530
|
context.eventEmitter.emit(itemEvent);
|
|
1180
|
-
|
|
1531
|
+
logger10.debug("Emitting queryInvalidatedEvent after action", {
|
|
1181
1532
|
eventType: "query_invalidated",
|
|
1182
1533
|
reason: "item_changed",
|
|
1183
1534
|
action: action2
|
|
@@ -1197,10 +1548,10 @@ import {
|
|
|
1197
1548
|
createAllActionWrapper
|
|
1198
1549
|
} from "@fjell/core";
|
|
1199
1550
|
import { NotFoundError as NotFoundError3 } from "@fjell/http-api";
|
|
1200
|
-
var
|
|
1551
|
+
var logger11 = logger_default.get("allAction");
|
|
1201
1552
|
var allAction = async (action2, body = {}, locations = [], context) => {
|
|
1202
1553
|
const { coordinate } = context;
|
|
1203
|
-
|
|
1554
|
+
logger11.default("allAction", { action: action2, body, locations });
|
|
1204
1555
|
const wrappedAllAction = createAllActionWrapper(
|
|
1205
1556
|
coordinate,
|
|
1206
1557
|
async (a, b, locs) => {
|
|
@@ -1220,10 +1571,10 @@ async function executeAllActionLogic(action2, body, locations, context) {
|
|
|
1220
1571
|
existingItems.push(...cachedItems);
|
|
1221
1572
|
}
|
|
1222
1573
|
} catch (error) {
|
|
1223
|
-
|
|
1574
|
+
logger11.debug("Could not retrieve existing items for comparison", { error });
|
|
1224
1575
|
}
|
|
1225
1576
|
}
|
|
1226
|
-
|
|
1577
|
+
logger11.debug("Invalidating location before allAction", { locations });
|
|
1227
1578
|
await cacheMap.invalidateLocation(locations);
|
|
1228
1579
|
let ret = [];
|
|
1229
1580
|
let affectedItems = [];
|
|
@@ -1233,7 +1584,7 @@ async function executeAllActionLogic(action2, body, locations, context) {
|
|
|
1233
1584
|
ret = result[0];
|
|
1234
1585
|
affectedItems = result[1];
|
|
1235
1586
|
} else {
|
|
1236
|
-
|
|
1587
|
+
logger11.warning("Unexpected result format from allAction", {
|
|
1237
1588
|
resultType: typeof result,
|
|
1238
1589
|
isArray: Array.isArray(result),
|
|
1239
1590
|
resultLength: Array.isArray(result) ? result.length : "not array"
|
|
@@ -1242,19 +1593,19 @@ async function executeAllActionLogic(action2, body, locations, context) {
|
|
|
1242
1593
|
affectedItems = [];
|
|
1243
1594
|
}
|
|
1244
1595
|
if (affectedItems && affectedItems.length > 0) {
|
|
1245
|
-
|
|
1596
|
+
logger11.debug("Handling cache invalidation for affected items", {
|
|
1246
1597
|
affectedItemsCount: affectedItems.length
|
|
1247
1598
|
});
|
|
1248
1599
|
try {
|
|
1249
1600
|
await handleActionCacheInvalidation(registry, affectedItems);
|
|
1250
1601
|
} catch (error) {
|
|
1251
|
-
|
|
1602
|
+
logger11.warning("Failed to handle cache invalidation for affected items", {
|
|
1252
1603
|
error: error instanceof Error ? error.message : String(error),
|
|
1253
1604
|
affectedItems
|
|
1254
1605
|
});
|
|
1255
1606
|
}
|
|
1256
1607
|
}
|
|
1257
|
-
|
|
1608
|
+
logger11.debug("Caching allAction results", { resultCount: ret.length });
|
|
1258
1609
|
const modifiedItems = [];
|
|
1259
1610
|
const newItems = [];
|
|
1260
1611
|
for (const v of ret) {
|
|
@@ -1276,7 +1627,7 @@ async function executeAllActionLogic(action2, body, locations, context) {
|
|
|
1276
1627
|
}
|
|
1277
1628
|
}
|
|
1278
1629
|
for (const item of modifiedItems) {
|
|
1279
|
-
|
|
1630
|
+
logger11.debug("Emitting item_updated event for modified item", { key: item.key });
|
|
1280
1631
|
const itemEvent = CacheEventFactory.itemUpdated(
|
|
1281
1632
|
item.key,
|
|
1282
1633
|
item,
|
|
@@ -1287,7 +1638,7 @@ async function executeAllActionLogic(action2, body, locations, context) {
|
|
|
1287
1638
|
eventEmitter.emit(itemEvent);
|
|
1288
1639
|
}
|
|
1289
1640
|
for (const item of newItems) {
|
|
1290
|
-
|
|
1641
|
+
logger11.debug("Emitting item_created event for new item", { key: item.key });
|
|
1291
1642
|
const itemEvent = CacheEventFactory.itemCreated(
|
|
1292
1643
|
item.key,
|
|
1293
1644
|
item,
|
|
@@ -1297,14 +1648,14 @@ async function executeAllActionLogic(action2, body, locations, context) {
|
|
|
1297
1648
|
}
|
|
1298
1649
|
if (modifiedItems.length > 0) {
|
|
1299
1650
|
const modifiedKeys = modifiedItems.map((item) => item.key);
|
|
1300
|
-
|
|
1651
|
+
logger11.debug("Invalidating individual item keys for modified items", {
|
|
1301
1652
|
keyCount: modifiedKeys.length,
|
|
1302
1653
|
keys: modifiedKeys
|
|
1303
1654
|
});
|
|
1304
1655
|
await cacheMap.invalidateItemKeys(modifiedKeys);
|
|
1305
1656
|
}
|
|
1306
1657
|
await cacheMap.clearQueryResults();
|
|
1307
|
-
|
|
1658
|
+
logger11.debug("Emitting query_invalidated event after allAction", {
|
|
1308
1659
|
eventType: "query_invalidated",
|
|
1309
1660
|
reason: "item_changed",
|
|
1310
1661
|
action: action2,
|
|
@@ -1337,10 +1688,10 @@ async function executeAllActionLogic(action2, body, locations, context) {
|
|
|
1337
1688
|
import {
|
|
1338
1689
|
createFacetWrapper
|
|
1339
1690
|
} from "@fjell/core";
|
|
1340
|
-
var
|
|
1691
|
+
var logger12 = logger_default.get("facet");
|
|
1341
1692
|
var facet = async (key, facet2, params = {}, context) => {
|
|
1342
1693
|
const { coordinate, api } = context;
|
|
1343
|
-
|
|
1694
|
+
logger12.default("facet", { key, facet: facet2 });
|
|
1344
1695
|
const wrappedFacet = createFacetWrapper(
|
|
1345
1696
|
coordinate,
|
|
1346
1697
|
async (k, f, p) => {
|
|
@@ -1354,10 +1705,10 @@ var facet = async (key, facet2, params = {}, context) => {
|
|
|
1354
1705
|
import {
|
|
1355
1706
|
createAllFacetWrapper
|
|
1356
1707
|
} from "@fjell/core";
|
|
1357
|
-
var
|
|
1708
|
+
var logger13 = logger_default.get("allFacet");
|
|
1358
1709
|
var allFacet = async (facet2, params = {}, locations = [], context) => {
|
|
1359
1710
|
const { api, coordinate } = context;
|
|
1360
|
-
|
|
1711
|
+
logger13.default("allFacet", { facet: facet2, params, locations });
|
|
1361
1712
|
const wrappedAllFacet = createAllFacetWrapper(
|
|
1362
1713
|
coordinate,
|
|
1363
1714
|
async (f, p, locs) => {
|
|
@@ -1371,10 +1722,10 @@ var allFacet = async (facet2, params = {}, locations = [], context) => {
|
|
|
1371
1722
|
import {
|
|
1372
1723
|
createFindWrapper
|
|
1373
1724
|
} from "@fjell/core";
|
|
1374
|
-
var
|
|
1725
|
+
var logger14 = logger_default.get("find");
|
|
1375
1726
|
var find = async (finder, params = {}, locations = [], context) => {
|
|
1376
1727
|
const { coordinate } = context;
|
|
1377
|
-
|
|
1728
|
+
logger14.default("find", { finder, params, locations });
|
|
1378
1729
|
const wrappedFind = createFindWrapper(
|
|
1379
1730
|
coordinate,
|
|
1380
1731
|
async (f, p, locs) => {
|
|
@@ -1387,21 +1738,21 @@ var find = async (finder, params = {}, locations = [], context) => {
|
|
|
1387
1738
|
async function executeFindLogic(finder, params, locations, context) {
|
|
1388
1739
|
const { api, cacheMap, pkType, ttlManager, eventEmitter } = context;
|
|
1389
1740
|
if (context.options?.bypassCache) {
|
|
1390
|
-
|
|
1741
|
+
logger14.debug("Cache bypass enabled, fetching directly from API", { finder, params, locations });
|
|
1391
1742
|
try {
|
|
1392
1743
|
const ret2 = await api.find(finder, params, locations);
|
|
1393
|
-
|
|
1744
|
+
logger14.debug("API response received (not cached due to bypass)", { finder, params, locations, itemCount: ret2.length });
|
|
1394
1745
|
return ret2;
|
|
1395
1746
|
} catch (error) {
|
|
1396
|
-
|
|
1747
|
+
logger14.error("API request failed", { finder, params, locations, error });
|
|
1397
1748
|
throw error;
|
|
1398
1749
|
}
|
|
1399
1750
|
}
|
|
1400
1751
|
const queryHash = createFinderHash(finder, params, locations);
|
|
1401
|
-
|
|
1752
|
+
logger14.debug("Generated query hash for find", { queryHash, finder, params, locations });
|
|
1402
1753
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
1403
1754
|
if (cachedItemKeys) {
|
|
1404
|
-
|
|
1755
|
+
logger14.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length, queryHash });
|
|
1405
1756
|
const cachedItems = [];
|
|
1406
1757
|
let allItemsAvailable = true;
|
|
1407
1758
|
for (const itemKey of cachedItemKeys) {
|
|
@@ -1416,7 +1767,7 @@ async function executeFindLogic(finder, params, locations, context) {
|
|
|
1416
1767
|
if (allItemsAvailable) {
|
|
1417
1768
|
return cachedItems;
|
|
1418
1769
|
} else {
|
|
1419
|
-
|
|
1770
|
+
logger14.debug("Some cached items missing, invalidating query cache");
|
|
1420
1771
|
cacheMap.deleteQueryResult(queryHash);
|
|
1421
1772
|
}
|
|
1422
1773
|
}
|
|
@@ -1433,7 +1784,7 @@ async function executeFindLogic(finder, params, locations, context) {
|
|
|
1433
1784
|
}
|
|
1434
1785
|
const itemKeys = ret.map((item) => item.key);
|
|
1435
1786
|
cacheMap.setQueryResult(queryHash, itemKeys);
|
|
1436
|
-
|
|
1787
|
+
logger14.debug("Cached query result", { queryHash, itemKeyCount: itemKeys.length });
|
|
1437
1788
|
const event = CacheEventFactory.createQueryEvent(params, locations, ret);
|
|
1438
1789
|
eventEmitter.emit(event);
|
|
1439
1790
|
return ret;
|
|
@@ -1443,10 +1794,10 @@ async function executeFindLogic(finder, params, locations, context) {
|
|
|
1443
1794
|
import {
|
|
1444
1795
|
createFindOneWrapper
|
|
1445
1796
|
} from "@fjell/core";
|
|
1446
|
-
var
|
|
1797
|
+
var logger15 = logger_default.get("findOne");
|
|
1447
1798
|
var findOne = async (finder, finderParams = {}, locations = [], context) => {
|
|
1448
1799
|
const { coordinate } = context;
|
|
1449
|
-
|
|
1800
|
+
logger15.default("findOne", { finder, finderParams, locations });
|
|
1450
1801
|
const wrappedFindOne = createFindOneWrapper(
|
|
1451
1802
|
coordinate,
|
|
1452
1803
|
async (f, p, locs) => {
|
|
@@ -1459,29 +1810,29 @@ var findOne = async (finder, finderParams = {}, locations = [], context) => {
|
|
|
1459
1810
|
async function executeFindOneLogic(finder, finderParams, locations, context) {
|
|
1460
1811
|
const { api, cacheMap, pkType, ttlManager, eventEmitter } = context;
|
|
1461
1812
|
if (context.options?.bypassCache) {
|
|
1462
|
-
|
|
1813
|
+
logger15.debug("Cache bypass enabled, fetching directly from API", { finder, finderParams, locations });
|
|
1463
1814
|
try {
|
|
1464
1815
|
const ret2 = await api.findOne(finder, finderParams, locations);
|
|
1465
1816
|
if (ret2 === null) {
|
|
1466
1817
|
throw new Error(`findOne returned null for finder: ${finder}`);
|
|
1467
1818
|
}
|
|
1468
|
-
|
|
1819
|
+
logger15.debug("API response received (not cached due to bypass)", { finder, finderParams, locations });
|
|
1469
1820
|
return ret2;
|
|
1470
1821
|
} catch (error) {
|
|
1471
|
-
|
|
1822
|
+
logger15.error("API request failed", { finder, finderParams, locations, error });
|
|
1472
1823
|
throw error;
|
|
1473
1824
|
}
|
|
1474
1825
|
}
|
|
1475
1826
|
const queryHash = createFinderHash(finder, finderParams, locations);
|
|
1476
|
-
|
|
1827
|
+
logger15.debug("Generated query hash for findOne", { queryHash });
|
|
1477
1828
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
1478
1829
|
if (cachedItemKeys && cachedItemKeys.length > 0) {
|
|
1479
|
-
|
|
1830
|
+
logger15.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
1480
1831
|
const item = await cacheMap.get(cachedItemKeys[0]);
|
|
1481
1832
|
if (item) {
|
|
1482
1833
|
return item;
|
|
1483
1834
|
} else {
|
|
1484
|
-
|
|
1835
|
+
logger15.debug("Cached item missing, invalidating query cache");
|
|
1485
1836
|
cacheMap.deleteQueryResult(queryHash);
|
|
1486
1837
|
}
|
|
1487
1838
|
}
|
|
@@ -1498,7 +1849,7 @@ async function executeFindOneLogic(finder, finderParams, locations, context) {
|
|
|
1498
1849
|
await cacheMap.delete(parsedKey);
|
|
1499
1850
|
}
|
|
1500
1851
|
cacheMap.setQueryResult(queryHash, [ret.key]);
|
|
1501
|
-
|
|
1852
|
+
logger15.debug("Cached query result", { queryHash, itemKey: ret.key });
|
|
1502
1853
|
const event = CacheEventFactory.createQueryEvent(finderParams, locations, [ret]);
|
|
1503
1854
|
eventEmitter.emit(event);
|
|
1504
1855
|
return ret;
|
|
@@ -1509,7 +1860,7 @@ import {
|
|
|
1509
1860
|
isItemKeyEqual,
|
|
1510
1861
|
isValidItemKey as isValidItemKey6
|
|
1511
1862
|
} from "@fjell/core";
|
|
1512
|
-
var
|
|
1863
|
+
var logger16 = logger_default.get("set");
|
|
1513
1864
|
var normalizeKeyValue2 = (value) => {
|
|
1514
1865
|
return String(value);
|
|
1515
1866
|
};
|
|
@@ -1559,13 +1910,13 @@ var normalizeKey = (key) => {
|
|
|
1559
1910
|
};
|
|
1560
1911
|
var set = async (key, v, context) => {
|
|
1561
1912
|
const { cacheMap, pkType, ttlManager, evictionManager, eventEmitter } = context;
|
|
1562
|
-
|
|
1913
|
+
logger16.default("set", { key, v });
|
|
1563
1914
|
if (!isValidItemKey6(key)) {
|
|
1564
|
-
|
|
1915
|
+
logger16.error("Key for Set is not a valid ItemKey: %j", key);
|
|
1565
1916
|
throw new Error("Key for Set is not a valid ItemKey");
|
|
1566
1917
|
}
|
|
1567
1918
|
if (!isItemKeyEqualNormalized(key, v.key)) {
|
|
1568
|
-
|
|
1919
|
+
logger16.error("Key does not match item key: %j != %j", key, v.key);
|
|
1569
1920
|
throw new Error("Key does not match item key");
|
|
1570
1921
|
}
|
|
1571
1922
|
const previousItem = await cacheMap.get(key);
|
|
@@ -1599,17 +1950,7 @@ import {
|
|
|
1599
1950
|
isComKey,
|
|
1600
1951
|
isQueryMatch
|
|
1601
1952
|
} from "@fjell/core";
|
|
1602
|
-
|
|
1603
|
-
// src/CacheMap.ts
|
|
1604
|
-
var CacheMap = class {
|
|
1605
|
-
types;
|
|
1606
|
-
constructor(types) {
|
|
1607
|
-
this.types = types;
|
|
1608
|
-
}
|
|
1609
|
-
};
|
|
1610
|
-
|
|
1611
|
-
// src/memory/MemoryCacheMap.ts
|
|
1612
|
-
var logger16 = logger_default.get("MemoryCacheMap");
|
|
1953
|
+
var logger17 = logger_default.get("MemoryCacheMap");
|
|
1613
1954
|
var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
1614
1955
|
implementationType = "memory/memory";
|
|
1615
1956
|
map = {};
|
|
@@ -1627,13 +1968,13 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1627
1968
|
const key = JSON.parse(keyStr);
|
|
1628
1969
|
this.set(key, value);
|
|
1629
1970
|
} catch (error) {
|
|
1630
|
-
|
|
1971
|
+
logger17.error("Failed to parse initial data key", { keyStr, error });
|
|
1631
1972
|
}
|
|
1632
1973
|
}
|
|
1633
1974
|
}
|
|
1634
1975
|
}
|
|
1635
1976
|
async get(key) {
|
|
1636
|
-
|
|
1977
|
+
logger17.trace("get", { key });
|
|
1637
1978
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1638
1979
|
const entry = this.map[hashedKey];
|
|
1639
1980
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
@@ -1648,7 +1989,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1648
1989
|
return null;
|
|
1649
1990
|
}
|
|
1650
1991
|
async set(key, value) {
|
|
1651
|
-
|
|
1992
|
+
logger17.trace("set", { key, value });
|
|
1652
1993
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1653
1994
|
const keyStr = JSON.stringify(key);
|
|
1654
1995
|
this.map[hashedKey] = { originalKey: key, value };
|
|
@@ -1675,7 +2016,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1675
2016
|
return !!entry && this.normalizedHashFunction(entry.originalKey) === hashedKey;
|
|
1676
2017
|
}
|
|
1677
2018
|
async delete(key) {
|
|
1678
|
-
|
|
2019
|
+
logger17.trace("delete", { key });
|
|
1679
2020
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1680
2021
|
const entry = this.map[hashedKey];
|
|
1681
2022
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
@@ -1704,10 +2045,10 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1704
2045
|
async allIn(locations) {
|
|
1705
2046
|
const allValues = await this.values();
|
|
1706
2047
|
if (locations.length === 0) {
|
|
1707
|
-
|
|
2048
|
+
logger17.debug("Returning all items, LocKeys is empty");
|
|
1708
2049
|
return allValues;
|
|
1709
2050
|
} else {
|
|
1710
|
-
|
|
2051
|
+
logger17.debug("allIn", { locations, count: allValues.length });
|
|
1711
2052
|
return allValues.filter((item) => {
|
|
1712
2053
|
const key = item.key;
|
|
1713
2054
|
if (key && isComKey(key)) {
|
|
@@ -1719,12 +2060,12 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1719
2060
|
}
|
|
1720
2061
|
}
|
|
1721
2062
|
async contains(query, locations) {
|
|
1722
|
-
|
|
2063
|
+
logger17.debug("contains", { query, locations });
|
|
1723
2064
|
const items = await this.allIn(locations);
|
|
1724
2065
|
return items.some((item) => isQueryMatch(item, query));
|
|
1725
2066
|
}
|
|
1726
2067
|
async queryIn(query, locations = []) {
|
|
1727
|
-
|
|
2068
|
+
logger17.debug("queryIn", { query, locations });
|
|
1728
2069
|
const items = await this.allIn(locations);
|
|
1729
2070
|
return items.filter((item) => isQueryMatch(item, query));
|
|
1730
2071
|
}
|
|
@@ -1747,7 +2088,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1747
2088
|
}
|
|
1748
2089
|
// Query result caching methods implementation
|
|
1749
2090
|
async setQueryResult(queryHash, itemKeys) {
|
|
1750
|
-
|
|
2091
|
+
logger17.trace("setQueryResult", { queryHash, itemKeys });
|
|
1751
2092
|
const entry = {
|
|
1752
2093
|
itemKeys: [...itemKeys]
|
|
1753
2094
|
// Create a copy to avoid external mutations
|
|
@@ -1755,7 +2096,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1755
2096
|
this.queryResultCache[queryHash] = entry;
|
|
1756
2097
|
}
|
|
1757
2098
|
async getQueryResult(queryHash) {
|
|
1758
|
-
|
|
2099
|
+
logger17.trace("getQueryResult", { queryHash });
|
|
1759
2100
|
const entry = this.queryResultCache[queryHash];
|
|
1760
2101
|
if (!entry) {
|
|
1761
2102
|
return null;
|
|
@@ -1767,11 +2108,11 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1767
2108
|
return !!entry;
|
|
1768
2109
|
}
|
|
1769
2110
|
async deleteQueryResult(queryHash) {
|
|
1770
|
-
|
|
2111
|
+
logger17.trace("deleteQueryResult", { queryHash });
|
|
1771
2112
|
delete this.queryResultCache[queryHash];
|
|
1772
2113
|
}
|
|
1773
2114
|
async invalidateItemKeys(keys) {
|
|
1774
|
-
|
|
2115
|
+
logger17.debug("invalidateItemKeys", { keys });
|
|
1775
2116
|
if (keys.length === 0) {
|
|
1776
2117
|
return;
|
|
1777
2118
|
}
|
|
@@ -1802,14 +2143,14 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1802
2143
|
queriesToRemove.forEach((queryHash) => {
|
|
1803
2144
|
this.deleteQueryResult(queryHash);
|
|
1804
2145
|
});
|
|
1805
|
-
|
|
2146
|
+
logger17.debug("Selectively invalidated queries referencing affected keys", {
|
|
1806
2147
|
affectedKeys: keys.length,
|
|
1807
2148
|
queriesRemoved: queriesToRemove.length,
|
|
1808
2149
|
totalQueries: Object.keys(this.queryResultCache).length
|
|
1809
2150
|
});
|
|
1810
2151
|
}
|
|
1811
2152
|
async invalidateLocation(locations) {
|
|
1812
|
-
|
|
2153
|
+
logger17.debug("invalidateLocation", { locations });
|
|
1813
2154
|
let keysToInvalidate = [];
|
|
1814
2155
|
if (locations.length === 0) {
|
|
1815
2156
|
const allKeys = await this.keys();
|
|
@@ -1822,7 +2163,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1822
2163
|
await this.invalidateItemKeys(keysToInvalidate);
|
|
1823
2164
|
}
|
|
1824
2165
|
async clearQueryResults() {
|
|
1825
|
-
|
|
2166
|
+
logger17.trace("clearQueryResults");
|
|
1826
2167
|
this.queryResultCache = {};
|
|
1827
2168
|
}
|
|
1828
2169
|
// CacheMapMetadataProvider implementation
|
|
@@ -1864,7 +2205,7 @@ import {
|
|
|
1864
2205
|
isComKey as isComKey2,
|
|
1865
2206
|
isQueryMatch as isQueryMatch2
|
|
1866
2207
|
} from "@fjell/core";
|
|
1867
|
-
var
|
|
2208
|
+
var logger18 = logger_default.get("EnhancedMemoryCacheMap");
|
|
1868
2209
|
var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
1869
2210
|
implementationType = "memory/enhanced";
|
|
1870
2211
|
map = {};
|
|
@@ -1883,11 +2224,11 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1883
2224
|
this.normalizedHashFunction = createNormalizedHashFunction();
|
|
1884
2225
|
if (sizeConfig?.maxSizeBytes) {
|
|
1885
2226
|
this.maxSizeBytes = parseSizeString(sizeConfig.maxSizeBytes);
|
|
1886
|
-
|
|
2227
|
+
logger18.debug("Cache size limit set", { maxSizeBytes: this.maxSizeBytes });
|
|
1887
2228
|
}
|
|
1888
2229
|
if (sizeConfig?.maxItems) {
|
|
1889
2230
|
this.maxItems = sizeConfig.maxItems;
|
|
1890
|
-
|
|
2231
|
+
logger18.debug("Cache item limit set", { maxItems: this.maxItems });
|
|
1891
2232
|
}
|
|
1892
2233
|
if (initialData) {
|
|
1893
2234
|
for (const [keyStr, value] of Object.entries(initialData)) {
|
|
@@ -1895,13 +2236,13 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1895
2236
|
const key = JSON.parse(keyStr);
|
|
1896
2237
|
this.set(key, value);
|
|
1897
2238
|
} catch (error) {
|
|
1898
|
-
|
|
2239
|
+
logger18.error("Failed to parse initial data key", { keyStr, error });
|
|
1899
2240
|
}
|
|
1900
2241
|
}
|
|
1901
2242
|
}
|
|
1902
2243
|
}
|
|
1903
2244
|
async get(key) {
|
|
1904
|
-
|
|
2245
|
+
logger18.trace("get", { key });
|
|
1905
2246
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1906
2247
|
const entry = this.map[hashedKey];
|
|
1907
2248
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey && entry.value !== null) {
|
|
@@ -1910,7 +2251,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1910
2251
|
return null;
|
|
1911
2252
|
}
|
|
1912
2253
|
async set(key, value) {
|
|
1913
|
-
|
|
2254
|
+
logger18.trace("set", { key, value });
|
|
1914
2255
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1915
2256
|
const estimatedSize = estimateValueSize(value);
|
|
1916
2257
|
const existingEntry = this.map[hashedKey];
|
|
@@ -1921,7 +2262,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1921
2262
|
const oldValue = existingEntry.value;
|
|
1922
2263
|
existingEntry.value = value;
|
|
1923
2264
|
existingEntry.metadata.estimatedSize = estimatedSize;
|
|
1924
|
-
|
|
2265
|
+
logger18.trace("Updated existing cache entry", {
|
|
1925
2266
|
key: hashedKey,
|
|
1926
2267
|
sizeDiff,
|
|
1927
2268
|
currentSize: this.currentSizeBytes,
|
|
@@ -1942,7 +2283,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1942
2283
|
};
|
|
1943
2284
|
this.currentSizeBytes += estimatedSize;
|
|
1944
2285
|
this.currentItemCount++;
|
|
1945
|
-
|
|
2286
|
+
logger18.trace("Added new cache entry", {
|
|
1946
2287
|
key: hashedKey,
|
|
1947
2288
|
size: estimatedSize,
|
|
1948
2289
|
currentSize: this.currentSizeBytes,
|
|
@@ -1959,14 +2300,14 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1959
2300
|
this.deleteInternal(key, true, "filter");
|
|
1960
2301
|
}
|
|
1961
2302
|
deleteInternal(key, invalidateQueries = false, invalidationMode = "remove") {
|
|
1962
|
-
|
|
2303
|
+
logger18.trace("delete", { key });
|
|
1963
2304
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1964
2305
|
const entry = this.map[hashedKey];
|
|
1965
2306
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
1966
2307
|
this.currentSizeBytes -= entry.metadata.estimatedSize;
|
|
1967
2308
|
this.currentItemCount--;
|
|
1968
2309
|
delete this.map[hashedKey];
|
|
1969
|
-
|
|
2310
|
+
logger18.trace("Deleted cache entry", {
|
|
1970
2311
|
key: hashedKey,
|
|
1971
2312
|
freedSize: entry.metadata.estimatedSize,
|
|
1972
2313
|
currentSize: this.currentSizeBytes,
|
|
@@ -1988,7 +2329,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1988
2329
|
return Object.values(this.map).filter((entry) => entry.value !== null).map((entry) => entry.value);
|
|
1989
2330
|
}
|
|
1990
2331
|
async clear() {
|
|
1991
|
-
|
|
2332
|
+
logger18.debug("Clearing cache", {
|
|
1992
2333
|
itemsCleared: this.currentItemCount,
|
|
1993
2334
|
bytesFreed: this.currentSizeBytes
|
|
1994
2335
|
});
|
|
@@ -1999,10 +2340,10 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1999
2340
|
async allIn(locations) {
|
|
2000
2341
|
const allValues = await this.values();
|
|
2001
2342
|
if (locations.length === 0) {
|
|
2002
|
-
|
|
2343
|
+
logger18.debug("Returning all items, LocKeys is empty");
|
|
2003
2344
|
return allValues;
|
|
2004
2345
|
} else {
|
|
2005
|
-
|
|
2346
|
+
logger18.debug("allIn", { locations, count: allValues.length });
|
|
2006
2347
|
return allValues.filter((item) => {
|
|
2007
2348
|
const key = item.key;
|
|
2008
2349
|
if (key && isComKey2(key)) {
|
|
@@ -2013,12 +2354,12 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2013
2354
|
}
|
|
2014
2355
|
}
|
|
2015
2356
|
async contains(query, locations) {
|
|
2016
|
-
|
|
2357
|
+
logger18.debug("contains", { query, locations });
|
|
2017
2358
|
const items = await this.allIn(locations);
|
|
2018
2359
|
return items.some((item) => isQueryMatch2(item, query));
|
|
2019
2360
|
}
|
|
2020
2361
|
async queryIn(query, locations = []) {
|
|
2021
|
-
|
|
2362
|
+
logger18.debug("queryIn", { query, locations });
|
|
2022
2363
|
const items = await this.allIn(locations);
|
|
2023
2364
|
return items.filter((item) => isQueryMatch2(item, query));
|
|
2024
2365
|
}
|
|
@@ -2064,7 +2405,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2064
2405
|
}
|
|
2065
2406
|
// Query result caching methods
|
|
2066
2407
|
async setQueryResult(queryHash, itemKeys) {
|
|
2067
|
-
|
|
2408
|
+
logger18.trace("setQueryResult", { queryHash, itemKeys });
|
|
2068
2409
|
if (queryHash in this.queryResultCache) {
|
|
2069
2410
|
this.removeQueryResultFromSizeTracking(queryHash);
|
|
2070
2411
|
}
|
|
@@ -2076,7 +2417,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2076
2417
|
this.addQueryResultToSizeTracking(queryHash, entry);
|
|
2077
2418
|
}
|
|
2078
2419
|
async getQueryResult(queryHash) {
|
|
2079
|
-
|
|
2420
|
+
logger18.trace("getQueryResult", { queryHash });
|
|
2080
2421
|
const entry = this.queryResultCache[queryHash];
|
|
2081
2422
|
if (!entry) {
|
|
2082
2423
|
return null;
|
|
@@ -2098,7 +2439,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2098
2439
|
this.queryResultsCacheSize = 0;
|
|
2099
2440
|
}
|
|
2100
2441
|
async invalidateItemKeys(keys) {
|
|
2101
|
-
|
|
2442
|
+
logger18.debug("invalidateItemKeys", { keys });
|
|
2102
2443
|
if (keys.length === 0) {
|
|
2103
2444
|
return;
|
|
2104
2445
|
}
|
|
@@ -2148,7 +2489,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2148
2489
|
});
|
|
2149
2490
|
}
|
|
2150
2491
|
async invalidateLocation(locations) {
|
|
2151
|
-
|
|
2492
|
+
logger18.debug("invalidateLocation", { locations });
|
|
2152
2493
|
let keysToInvalidate = [];
|
|
2153
2494
|
if (locations.length === 0) {
|
|
2154
2495
|
const allKeys = await this.keys();
|
|
@@ -2168,7 +2509,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2168
2509
|
const itemKeysSize = estimateValueSize(entry.itemKeys);
|
|
2169
2510
|
const totalSize = hashSize + itemKeysSize;
|
|
2170
2511
|
this.queryResultsCacheSize += totalSize;
|
|
2171
|
-
|
|
2512
|
+
logger18.trace("Added query result to size tracking", {
|
|
2172
2513
|
queryHash,
|
|
2173
2514
|
estimatedSize: totalSize,
|
|
2174
2515
|
totalQueryCacheSize: this.queryResultsCacheSize
|
|
@@ -2184,7 +2525,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2184
2525
|
const itemKeysSize = estimateValueSize(entry.itemKeys);
|
|
2185
2526
|
const totalSize = hashSize + itemKeysSize;
|
|
2186
2527
|
this.queryResultsCacheSize = Math.max(0, this.queryResultsCacheSize - totalSize);
|
|
2187
|
-
|
|
2528
|
+
logger18.trace("Removed query result from size tracking", {
|
|
2188
2529
|
queryHash,
|
|
2189
2530
|
estimatedSize: totalSize,
|
|
2190
2531
|
totalQueryCacheSize: this.queryResultsCacheSize
|
|
@@ -2269,7 +2610,7 @@ import {
|
|
|
2269
2610
|
isComKey as isComKey3,
|
|
2270
2611
|
isQueryMatch as isQueryMatch3
|
|
2271
2612
|
} from "@fjell/core";
|
|
2272
|
-
var
|
|
2613
|
+
var logger19 = logger_default.get("LocalStorageCacheMap");
|
|
2273
2614
|
var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
2274
2615
|
implementationType = "browser/localStorage";
|
|
2275
2616
|
keyPrefix;
|
|
@@ -2300,7 +2641,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2300
2641
|
}
|
|
2301
2642
|
return keys;
|
|
2302
2643
|
} catch (error) {
|
|
2303
|
-
|
|
2644
|
+
logger19.error("Error getting keys by prefix from localStorage", { prefix, error });
|
|
2304
2645
|
throw error;
|
|
2305
2646
|
}
|
|
2306
2647
|
}
|
|
@@ -2308,12 +2649,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2308
2649
|
try {
|
|
2309
2650
|
const allEntries = this.collectCacheEntries();
|
|
2310
2651
|
if (allEntries.length === 0) {
|
|
2311
|
-
|
|
2652
|
+
logger19.debug("No entries to clean up");
|
|
2312
2653
|
return false;
|
|
2313
2654
|
}
|
|
2314
2655
|
return this.removeOldestEntries(allEntries, aggressive);
|
|
2315
2656
|
} catch (error) {
|
|
2316
|
-
|
|
2657
|
+
logger19.error("Failed to cleanup old localStorage entries", { error });
|
|
2317
2658
|
return false;
|
|
2318
2659
|
}
|
|
2319
2660
|
}
|
|
@@ -2339,7 +2680,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2339
2680
|
}
|
|
2340
2681
|
}
|
|
2341
2682
|
} catch (error) {
|
|
2342
|
-
|
|
2683
|
+
logger19.debug("Found corrupted entry during cleanup", { key, error });
|
|
2343
2684
|
allEntries.push({ key, timestamp: 0, size: 0 });
|
|
2344
2685
|
}
|
|
2345
2686
|
}
|
|
@@ -2358,12 +2699,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2358
2699
|
removedCount++;
|
|
2359
2700
|
removedSize += allEntries[i].size;
|
|
2360
2701
|
} catch (error) {
|
|
2361
|
-
|
|
2702
|
+
logger19.error("Failed to remove entry during cleanup", { key: allEntries[i].key, error });
|
|
2362
2703
|
}
|
|
2363
2704
|
}
|
|
2364
2705
|
if (removedCount > 0) {
|
|
2365
2706
|
const cleanupType = aggressive ? "aggressive" : "normal";
|
|
2366
|
-
|
|
2707
|
+
logger19.info(`Cleaned up ${removedCount} old localStorage entries (${removedSize} bytes) using ${cleanupType} cleanup to free space`);
|
|
2367
2708
|
}
|
|
2368
2709
|
return removedCount > 0;
|
|
2369
2710
|
}
|
|
@@ -2371,7 +2712,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2371
2712
|
return this.getAllKeysStartingWith(`${this.keyPrefix}:`);
|
|
2372
2713
|
}
|
|
2373
2714
|
async get(key) {
|
|
2374
|
-
|
|
2715
|
+
logger19.trace("get", { key });
|
|
2375
2716
|
try {
|
|
2376
2717
|
const storageKey = this.getStorageKey(key);
|
|
2377
2718
|
let stored = localStorage.getItem(storageKey);
|
|
@@ -2386,18 +2727,18 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2386
2727
|
return parsed.value;
|
|
2387
2728
|
}
|
|
2388
2729
|
} catch (parseError) {
|
|
2389
|
-
|
|
2730
|
+
logger19.debug("Failed to parse stored value", { key, error: parseError });
|
|
2390
2731
|
return null;
|
|
2391
2732
|
}
|
|
2392
2733
|
}
|
|
2393
2734
|
return null;
|
|
2394
2735
|
} catch (error) {
|
|
2395
|
-
|
|
2736
|
+
logger19.error("Error retrieving from localStorage", { key, error });
|
|
2396
2737
|
return null;
|
|
2397
2738
|
}
|
|
2398
2739
|
}
|
|
2399
2740
|
async set(key, value) {
|
|
2400
|
-
|
|
2741
|
+
logger19.trace("set", { key, value });
|
|
2401
2742
|
for (let attempt = 0; attempt < this.MAX_RETRY_ATTEMPTS; attempt++) {
|
|
2402
2743
|
try {
|
|
2403
2744
|
const storageKey = this.getStorageKey(key);
|
|
@@ -2408,12 +2749,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2408
2749
|
};
|
|
2409
2750
|
localStorage.setItem(storageKey, JSON.stringify(toStore));
|
|
2410
2751
|
if (attempt > 0) {
|
|
2411
|
-
|
|
2752
|
+
logger19.info(`Successfully stored item after ${attempt} retries`);
|
|
2412
2753
|
}
|
|
2413
2754
|
return;
|
|
2414
2755
|
} catch (error) {
|
|
2415
2756
|
const isLastAttempt = attempt === this.MAX_RETRY_ATTEMPTS - 1;
|
|
2416
|
-
|
|
2757
|
+
logger19.error(`Error storing to localStorage (attempt ${attempt + 1}/${this.MAX_RETRY_ATTEMPTS})`, {
|
|
2417
2758
|
key,
|
|
2418
2759
|
value,
|
|
2419
2760
|
error,
|
|
@@ -2440,30 +2781,30 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2440
2781
|
const parsed = JSON.parse(stored);
|
|
2441
2782
|
return this.normalizedHashFunction(parsed.originalKey) === this.normalizedHashFunction(key);
|
|
2442
2783
|
} catch (parseError) {
|
|
2443
|
-
|
|
2784
|
+
logger19.debug("Failed to parse stored value in includesKey", { key, error: parseError });
|
|
2444
2785
|
return false;
|
|
2445
2786
|
}
|
|
2446
2787
|
}
|
|
2447
2788
|
return false;
|
|
2448
2789
|
} catch (error) {
|
|
2449
|
-
|
|
2790
|
+
logger19.error("Error checking key in localStorage", { key, error });
|
|
2450
2791
|
return false;
|
|
2451
2792
|
}
|
|
2452
2793
|
}
|
|
2453
2794
|
async delete(key) {
|
|
2454
|
-
|
|
2795
|
+
logger19.trace("delete", { key });
|
|
2455
2796
|
try {
|
|
2456
2797
|
const storageKey = this.getStorageKey(key);
|
|
2457
2798
|
localStorage.removeItem(storageKey);
|
|
2458
2799
|
} catch (error) {
|
|
2459
|
-
|
|
2800
|
+
logger19.error("Error deleting from localStorage", { key, error });
|
|
2460
2801
|
throw error;
|
|
2461
2802
|
}
|
|
2462
2803
|
}
|
|
2463
2804
|
async allIn(locations) {
|
|
2464
2805
|
const allKeys = this.keys();
|
|
2465
2806
|
if (locations.length === 0) {
|
|
2466
|
-
|
|
2807
|
+
logger19.debug("Returning all items, LocKeys is empty");
|
|
2467
2808
|
const items = [];
|
|
2468
2809
|
for (const key of await allKeys) {
|
|
2469
2810
|
const item = await this.get(key);
|
|
@@ -2475,10 +2816,10 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2475
2816
|
} else {
|
|
2476
2817
|
const locKeys = locations;
|
|
2477
2818
|
const resolvedKeys = await allKeys;
|
|
2478
|
-
|
|
2819
|
+
logger19.debug("allIn", { locKeys, keys: resolvedKeys.length });
|
|
2479
2820
|
const filteredKeys = resolvedKeys.filter((key) => key && isComKey3(key)).filter((key) => {
|
|
2480
2821
|
const ComKey16 = key;
|
|
2481
|
-
|
|
2822
|
+
logger19.debug("Comparing Location Keys", {
|
|
2482
2823
|
locKeys,
|
|
2483
2824
|
ComKey: ComKey16
|
|
2484
2825
|
});
|
|
@@ -2495,12 +2836,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2495
2836
|
}
|
|
2496
2837
|
}
|
|
2497
2838
|
async contains(query, locations) {
|
|
2498
|
-
|
|
2839
|
+
logger19.debug("contains", { query, locations });
|
|
2499
2840
|
const items = await this.allIn(locations);
|
|
2500
2841
|
return items.some((item) => isQueryMatch3(item, query));
|
|
2501
2842
|
}
|
|
2502
2843
|
async queryIn(query, locations = []) {
|
|
2503
|
-
|
|
2844
|
+
logger19.debug("queryIn", { query, locations });
|
|
2504
2845
|
const items = await this.allIn(locations);
|
|
2505
2846
|
return items.filter((item) => isQueryMatch3(item, query));
|
|
2506
2847
|
}
|
|
@@ -2514,7 +2855,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2514
2855
|
return JSON.parse(stored);
|
|
2515
2856
|
}
|
|
2516
2857
|
} catch (parseError) {
|
|
2517
|
-
|
|
2858
|
+
logger19.debug("Skipping corrupted localStorage entry", { storageKey, error: parseError });
|
|
2518
2859
|
}
|
|
2519
2860
|
return null;
|
|
2520
2861
|
}
|
|
@@ -2529,7 +2870,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2529
2870
|
}
|
|
2530
2871
|
}
|
|
2531
2872
|
} catch (error) {
|
|
2532
|
-
|
|
2873
|
+
logger19.error("Error getting keys from localStorage", { error });
|
|
2533
2874
|
}
|
|
2534
2875
|
return keys;
|
|
2535
2876
|
}
|
|
@@ -2544,25 +2885,25 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2544
2885
|
}
|
|
2545
2886
|
}
|
|
2546
2887
|
} catch (error) {
|
|
2547
|
-
|
|
2888
|
+
logger19.error("Error getting values from localStorage", { error });
|
|
2548
2889
|
}
|
|
2549
2890
|
return values;
|
|
2550
2891
|
}
|
|
2551
2892
|
async clear() {
|
|
2552
|
-
|
|
2893
|
+
logger19.debug("Clearing localStorage cache");
|
|
2553
2894
|
try {
|
|
2554
2895
|
const storageKeys = this.getAllStorageKeys();
|
|
2555
2896
|
for (const storageKey of storageKeys) {
|
|
2556
2897
|
localStorage.removeItem(storageKey);
|
|
2557
2898
|
}
|
|
2558
2899
|
} catch (error) {
|
|
2559
|
-
|
|
2900
|
+
logger19.error("Error clearing localStorage cache", { error });
|
|
2560
2901
|
throw error;
|
|
2561
2902
|
}
|
|
2562
2903
|
}
|
|
2563
2904
|
// Query result caching methods implementation
|
|
2564
2905
|
async setQueryResult(queryHash, itemKeys) {
|
|
2565
|
-
|
|
2906
|
+
logger19.trace("setQueryResult", { queryHash, itemKeys });
|
|
2566
2907
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2567
2908
|
const entry = {
|
|
2568
2909
|
itemKeys
|
|
@@ -2570,11 +2911,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2570
2911
|
try {
|
|
2571
2912
|
localStorage.setItem(queryKey, JSON.stringify(entry));
|
|
2572
2913
|
} catch (error) {
|
|
2573
|
-
|
|
2914
|
+
logger19.error("Failed to store query result in localStorage", { queryHash, error });
|
|
2574
2915
|
}
|
|
2575
2916
|
}
|
|
2576
2917
|
async getQueryResult(queryHash) {
|
|
2577
|
-
|
|
2918
|
+
logger19.trace("getQueryResult", { queryHash });
|
|
2578
2919
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2579
2920
|
try {
|
|
2580
2921
|
const data = localStorage.getItem(queryKey);
|
|
@@ -2587,7 +2928,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2587
2928
|
}
|
|
2588
2929
|
return entry.itemKeys || null;
|
|
2589
2930
|
} catch (error) {
|
|
2590
|
-
|
|
2931
|
+
logger19.error("Failed to retrieve query result from localStorage", { queryHash, error });
|
|
2591
2932
|
return null;
|
|
2592
2933
|
}
|
|
2593
2934
|
}
|
|
@@ -2596,21 +2937,21 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2596
2937
|
try {
|
|
2597
2938
|
return localStorage.getItem(queryKey) !== null;
|
|
2598
2939
|
} catch (error) {
|
|
2599
|
-
|
|
2940
|
+
logger19.error("Failed to check query result in localStorage", { queryHash, error });
|
|
2600
2941
|
return false;
|
|
2601
2942
|
}
|
|
2602
2943
|
}
|
|
2603
2944
|
async deleteQueryResult(queryHash) {
|
|
2604
|
-
|
|
2945
|
+
logger19.trace("deleteQueryResult", { queryHash });
|
|
2605
2946
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2606
2947
|
try {
|
|
2607
2948
|
localStorage.removeItem(queryKey);
|
|
2608
2949
|
} catch (error) {
|
|
2609
|
-
|
|
2950
|
+
logger19.error("Failed to delete query result from localStorage", { queryHash, error });
|
|
2610
2951
|
}
|
|
2611
2952
|
}
|
|
2612
2953
|
async invalidateItemKeys(keys) {
|
|
2613
|
-
|
|
2954
|
+
logger19.debug("invalidateItemKeys", { keys });
|
|
2614
2955
|
if (keys.length === 0) {
|
|
2615
2956
|
return;
|
|
2616
2957
|
}
|
|
@@ -2648,24 +2989,24 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2648
2989
|
}
|
|
2649
2990
|
}
|
|
2650
2991
|
} catch (error) {
|
|
2651
|
-
|
|
2992
|
+
logger19.debug("Failed to parse query result", { queryKey, error });
|
|
2652
2993
|
}
|
|
2653
2994
|
}
|
|
2654
2995
|
queriesToRemove.forEach((queryKey) => {
|
|
2655
2996
|
localStorage.removeItem(queryKey);
|
|
2656
2997
|
});
|
|
2657
|
-
|
|
2998
|
+
logger19.debug("Selectively invalidated queries referencing affected keys", {
|
|
2658
2999
|
affectedKeys: keys.length,
|
|
2659
3000
|
queriesRemoved: queriesToRemove.length,
|
|
2660
3001
|
totalQueries: queryKeys.length
|
|
2661
3002
|
});
|
|
2662
3003
|
} catch (error) {
|
|
2663
|
-
|
|
3004
|
+
logger19.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
2664
3005
|
await this.clearQueryResults();
|
|
2665
3006
|
}
|
|
2666
3007
|
}
|
|
2667
3008
|
async invalidateLocation(locations) {
|
|
2668
|
-
|
|
3009
|
+
logger19.debug("invalidateLocation", { locations });
|
|
2669
3010
|
let keysToInvalidate = [];
|
|
2670
3011
|
if (locations.length === 0) {
|
|
2671
3012
|
const allKeys = await this.keys();
|
|
@@ -2680,7 +3021,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2680
3021
|
}
|
|
2681
3022
|
}
|
|
2682
3023
|
async clearQueryResults() {
|
|
2683
|
-
|
|
3024
|
+
logger19.trace("clearQueryResults");
|
|
2684
3025
|
const queryPrefix = `${this.keyPrefix}:query:`;
|
|
2685
3026
|
try {
|
|
2686
3027
|
const keysToRemove = this.getAllKeysStartingWith(queryPrefix);
|
|
@@ -2688,11 +3029,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2688
3029
|
try {
|
|
2689
3030
|
localStorage.removeItem(key);
|
|
2690
3031
|
} catch (error) {
|
|
2691
|
-
|
|
3032
|
+
logger19.error("Failed to remove query result from localStorage", { key, error });
|
|
2692
3033
|
}
|
|
2693
3034
|
}
|
|
2694
3035
|
} catch (error) {
|
|
2695
|
-
|
|
3036
|
+
logger19.error("Failed to clear query results from localStorage", { error });
|
|
2696
3037
|
}
|
|
2697
3038
|
}
|
|
2698
3039
|
// CacheMapMetadataProvider implementation
|
|
@@ -2704,13 +3045,13 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2704
3045
|
try {
|
|
2705
3046
|
return JSON.parse(stored);
|
|
2706
3047
|
} catch (e) {
|
|
2707
|
-
|
|
3048
|
+
logger19.debug("Invalid metadata JSON, treating as null", { key, error: e });
|
|
2708
3049
|
return null;
|
|
2709
3050
|
}
|
|
2710
3051
|
}
|
|
2711
3052
|
return null;
|
|
2712
3053
|
} catch (error) {
|
|
2713
|
-
|
|
3054
|
+
logger19.error("Error getting metadata from localStorage", { key, error });
|
|
2714
3055
|
throw error;
|
|
2715
3056
|
}
|
|
2716
3057
|
}
|
|
@@ -2720,12 +3061,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2720
3061
|
const metadataKey = `${this.keyPrefix}:metadata:${key}`;
|
|
2721
3062
|
localStorage.setItem(metadataKey, JSON.stringify(metadata));
|
|
2722
3063
|
if (attempt > 0) {
|
|
2723
|
-
|
|
3064
|
+
logger19.info(`Successfully stored metadata after ${attempt} retries`);
|
|
2724
3065
|
}
|
|
2725
3066
|
return;
|
|
2726
3067
|
} catch (error) {
|
|
2727
3068
|
const isLastAttempt = attempt === this.MAX_RETRY_ATTEMPTS - 1;
|
|
2728
|
-
|
|
3069
|
+
logger19.error(`Error storing metadata to localStorage (attempt ${attempt + 1}/${this.MAX_RETRY_ATTEMPTS})`, {
|
|
2729
3070
|
key,
|
|
2730
3071
|
error,
|
|
2731
3072
|
isLastAttempt
|
|
@@ -2747,7 +3088,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2747
3088
|
const metadataKey = `${this.keyPrefix}:metadata:${key}`;
|
|
2748
3089
|
localStorage.removeItem(metadataKey);
|
|
2749
3090
|
} catch (error) {
|
|
2750
|
-
|
|
3091
|
+
logger19.error("Error deleting metadata from localStorage", { key, error });
|
|
2751
3092
|
throw error;
|
|
2752
3093
|
}
|
|
2753
3094
|
}
|
|
@@ -2766,11 +3107,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2766
3107
|
metadata.set(metadataKey, parsed);
|
|
2767
3108
|
}
|
|
2768
3109
|
} catch (error) {
|
|
2769
|
-
|
|
3110
|
+
logger19.debug("Skipping invalid metadata entry", { key, error });
|
|
2770
3111
|
}
|
|
2771
3112
|
}
|
|
2772
3113
|
} catch (error) {
|
|
2773
|
-
|
|
3114
|
+
logger19.error("Error getting metadata from localStorage", { error });
|
|
2774
3115
|
throw error;
|
|
2775
3116
|
}
|
|
2776
3117
|
return metadata;
|
|
@@ -2781,7 +3122,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2781
3122
|
const keysToDelete = this.getAllKeysStartingWith(metadataPrefix);
|
|
2782
3123
|
keysToDelete.forEach((key) => localStorage.removeItem(key));
|
|
2783
3124
|
} catch (error) {
|
|
2784
|
-
|
|
3125
|
+
logger19.error("Error clearing metadata from localStorage", { error });
|
|
2785
3126
|
throw error;
|
|
2786
3127
|
}
|
|
2787
3128
|
}
|
|
@@ -2808,16 +3149,16 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2808
3149
|
itemCount++;
|
|
2809
3150
|
}
|
|
2810
3151
|
} catch (error) {
|
|
2811
|
-
|
|
3152
|
+
logger19.debug("Invalid entry in getCurrentSize", { key, error });
|
|
2812
3153
|
}
|
|
2813
3154
|
}
|
|
2814
3155
|
} catch (error) {
|
|
2815
|
-
|
|
3156
|
+
logger19.debug("Size calculation failed, using string length", { key, error });
|
|
2816
3157
|
sizeBytes += value.length;
|
|
2817
3158
|
}
|
|
2818
3159
|
}
|
|
2819
3160
|
} catch (error) {
|
|
2820
|
-
|
|
3161
|
+
logger19.error("Error calculating size from localStorage", { error });
|
|
2821
3162
|
throw error;
|
|
2822
3163
|
}
|
|
2823
3164
|
return { itemCount, sizeBytes };
|
|
@@ -2838,7 +3179,7 @@ import {
|
|
|
2838
3179
|
isQueryMatch as isQueryMatch4
|
|
2839
3180
|
} from "@fjell/core";
|
|
2840
3181
|
import safeStringify2 from "fast-safe-stringify";
|
|
2841
|
-
var
|
|
3182
|
+
var logger20 = logger_default.get("SessionStorageCacheMap");
|
|
2842
3183
|
var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
2843
3184
|
implementationType = "browser/sessionStorage";
|
|
2844
3185
|
keyPrefix;
|
|
@@ -2866,7 +3207,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2866
3207
|
}
|
|
2867
3208
|
}
|
|
2868
3209
|
} catch (error) {
|
|
2869
|
-
|
|
3210
|
+
logger20.error("Error getting keys from sessionStorage", { error });
|
|
2870
3211
|
}
|
|
2871
3212
|
return keys;
|
|
2872
3213
|
}
|
|
@@ -2889,7 +3230,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2889
3230
|
}
|
|
2890
3231
|
}
|
|
2891
3232
|
async get(key) {
|
|
2892
|
-
|
|
3233
|
+
logger20.trace("get", { key });
|
|
2893
3234
|
try {
|
|
2894
3235
|
const currentHash = this.normalizedHashFunction(key);
|
|
2895
3236
|
if (this.hasCollisionForHash(currentHash)) {
|
|
@@ -2909,14 +3250,14 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2909
3250
|
}
|
|
2910
3251
|
return null;
|
|
2911
3252
|
} catch (error) {
|
|
2912
|
-
|
|
3253
|
+
logger20.error("Error retrieving from sessionStorage", { key, error });
|
|
2913
3254
|
return null;
|
|
2914
3255
|
}
|
|
2915
3256
|
}
|
|
2916
3257
|
async set(key, value) {
|
|
2917
3258
|
try {
|
|
2918
3259
|
const storageKey = this.getStorageKey(key);
|
|
2919
|
-
|
|
3260
|
+
logger20.trace("set", { storageKey });
|
|
2920
3261
|
const toStore = {
|
|
2921
3262
|
originalKey: key,
|
|
2922
3263
|
value,
|
|
@@ -2926,7 +3267,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2926
3267
|
const jsonString = safeStringify2(toStore);
|
|
2927
3268
|
sessionStorage.setItem(storageKey, jsonString);
|
|
2928
3269
|
} catch (error) {
|
|
2929
|
-
|
|
3270
|
+
logger20.error("Error storing to sessionStorage", { errorMessage: error?.message });
|
|
2930
3271
|
throw new Error(`Failed to store item in sessionStorage: ${error}`);
|
|
2931
3272
|
}
|
|
2932
3273
|
}
|
|
@@ -2947,23 +3288,23 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2947
3288
|
}
|
|
2948
3289
|
return false;
|
|
2949
3290
|
} catch (error) {
|
|
2950
|
-
|
|
3291
|
+
logger20.error("Error checking key in sessionStorage", { key, error });
|
|
2951
3292
|
return false;
|
|
2952
3293
|
}
|
|
2953
3294
|
}
|
|
2954
3295
|
async delete(key) {
|
|
2955
|
-
|
|
3296
|
+
logger20.trace("delete", { key });
|
|
2956
3297
|
try {
|
|
2957
3298
|
const storageKey = this.getStorageKey(key);
|
|
2958
3299
|
sessionStorage.removeItem(storageKey);
|
|
2959
3300
|
} catch (error) {
|
|
2960
|
-
|
|
3301
|
+
logger20.error("Error deleting from sessionStorage", { key, error });
|
|
2961
3302
|
}
|
|
2962
3303
|
}
|
|
2963
3304
|
async allIn(locations) {
|
|
2964
3305
|
const allKeys = this.keys();
|
|
2965
3306
|
if (locations.length === 0) {
|
|
2966
|
-
|
|
3307
|
+
logger20.debug("Returning all items, LocKeys is empty");
|
|
2967
3308
|
const items = [];
|
|
2968
3309
|
for (const key of await allKeys) {
|
|
2969
3310
|
const item = await this.get(key);
|
|
@@ -2975,10 +3316,10 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2975
3316
|
} else {
|
|
2976
3317
|
const locKeys = locations;
|
|
2977
3318
|
const resolvedKeys = await allKeys;
|
|
2978
|
-
|
|
3319
|
+
logger20.debug("allIn", { locKeys, keys: resolvedKeys.length });
|
|
2979
3320
|
const filteredKeys = resolvedKeys.filter((key) => key && isComKey4(key)).filter((key) => {
|
|
2980
3321
|
const ComKey16 = key;
|
|
2981
|
-
|
|
3322
|
+
logger20.debug("Comparing Location Keys", {
|
|
2982
3323
|
locKeys,
|
|
2983
3324
|
ComKey: ComKey16
|
|
2984
3325
|
});
|
|
@@ -2995,12 +3336,12 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2995
3336
|
}
|
|
2996
3337
|
}
|
|
2997
3338
|
async contains(query, locations) {
|
|
2998
|
-
|
|
3339
|
+
logger20.debug("contains", { query, locations });
|
|
2999
3340
|
const items = await this.allIn(locations);
|
|
3000
3341
|
return items.some((item) => isQueryMatch4(item, query));
|
|
3001
3342
|
}
|
|
3002
3343
|
async queryIn(query, locations = []) {
|
|
3003
|
-
|
|
3344
|
+
logger20.debug("queryIn", { query, locations });
|
|
3004
3345
|
const items = await this.allIn(locations);
|
|
3005
3346
|
return items.filter((item) => isQueryMatch4(item, query));
|
|
3006
3347
|
}
|
|
@@ -3020,11 +3361,11 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3020
3361
|
keys.push(parsed.originalKey);
|
|
3021
3362
|
}
|
|
3022
3363
|
} catch (itemError) {
|
|
3023
|
-
|
|
3364
|
+
logger20.trace("Skipping invalid storage item", { storageKey, error: itemError });
|
|
3024
3365
|
}
|
|
3025
3366
|
}
|
|
3026
3367
|
} catch (error) {
|
|
3027
|
-
|
|
3368
|
+
logger20.error("Error getting keys from sessionStorage", { error });
|
|
3028
3369
|
}
|
|
3029
3370
|
return keys;
|
|
3030
3371
|
}
|
|
@@ -3041,28 +3382,28 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3041
3382
|
values.push(parsed.value);
|
|
3042
3383
|
}
|
|
3043
3384
|
} catch (itemError) {
|
|
3044
|
-
|
|
3385
|
+
logger20.trace("Skipping invalid storage item for values", { storageKey, error: itemError });
|
|
3045
3386
|
}
|
|
3046
3387
|
}
|
|
3047
3388
|
} catch (error) {
|
|
3048
|
-
|
|
3389
|
+
logger20.error("Error getting values from sessionStorage", { error });
|
|
3049
3390
|
}
|
|
3050
3391
|
return values;
|
|
3051
3392
|
}
|
|
3052
3393
|
async clear() {
|
|
3053
|
-
|
|
3394
|
+
logger20.debug("Clearing sessionStorage cache");
|
|
3054
3395
|
try {
|
|
3055
3396
|
const storageKeys = this.getAllStorageKeys();
|
|
3056
3397
|
for (const storageKey of storageKeys) {
|
|
3057
3398
|
sessionStorage.removeItem(storageKey);
|
|
3058
3399
|
}
|
|
3059
3400
|
} catch (error) {
|
|
3060
|
-
|
|
3401
|
+
logger20.error("Error clearing sessionStorage cache", { error });
|
|
3061
3402
|
}
|
|
3062
3403
|
}
|
|
3063
3404
|
// Query result caching methods implementation
|
|
3064
3405
|
async setQueryResult(queryHash, itemKeys) {
|
|
3065
|
-
|
|
3406
|
+
logger20.trace("setQueryResult", { queryHash, itemKeys });
|
|
3066
3407
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
3067
3408
|
const entry = {
|
|
3068
3409
|
itemKeys
|
|
@@ -3071,11 +3412,11 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3071
3412
|
const jsonString = safeStringify2(entry);
|
|
3072
3413
|
sessionStorage.setItem(queryKey, jsonString);
|
|
3073
3414
|
} catch (error) {
|
|
3074
|
-
|
|
3415
|
+
logger20.error("Failed to store query result in sessionStorage", { queryHash, error });
|
|
3075
3416
|
}
|
|
3076
3417
|
}
|
|
3077
3418
|
async getQueryResult(queryHash) {
|
|
3078
|
-
|
|
3419
|
+
logger20.trace("getQueryResult", { queryHash });
|
|
3079
3420
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
3080
3421
|
try {
|
|
3081
3422
|
const data = sessionStorage.getItem(queryKey);
|
|
@@ -3088,7 +3429,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3088
3429
|
}
|
|
3089
3430
|
return entry.itemKeys || null;
|
|
3090
3431
|
} catch (error) {
|
|
3091
|
-
|
|
3432
|
+
logger20.error("Failed to retrieve query result from sessionStorage", { queryHash, error });
|
|
3092
3433
|
return null;
|
|
3093
3434
|
}
|
|
3094
3435
|
}
|
|
@@ -3097,21 +3438,21 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3097
3438
|
try {
|
|
3098
3439
|
return sessionStorage.getItem(queryKey) !== null;
|
|
3099
3440
|
} catch (error) {
|
|
3100
|
-
|
|
3441
|
+
logger20.error("Failed to check query result in sessionStorage", { queryHash, error });
|
|
3101
3442
|
return false;
|
|
3102
3443
|
}
|
|
3103
3444
|
}
|
|
3104
3445
|
async deleteQueryResult(queryHash) {
|
|
3105
|
-
|
|
3446
|
+
logger20.trace("deleteQueryResult", { queryHash });
|
|
3106
3447
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
3107
3448
|
try {
|
|
3108
3449
|
sessionStorage.removeItem(queryKey);
|
|
3109
3450
|
} catch (error) {
|
|
3110
|
-
|
|
3451
|
+
logger20.error("Failed to delete query result from sessionStorage", { queryHash, error });
|
|
3111
3452
|
}
|
|
3112
3453
|
}
|
|
3113
3454
|
async clearQueryResults() {
|
|
3114
|
-
|
|
3455
|
+
logger20.trace("clearQueryResults");
|
|
3115
3456
|
const queryPrefix = `${this.keyPrefix}:query:`;
|
|
3116
3457
|
try {
|
|
3117
3458
|
const keysToRemove = [];
|
|
@@ -3123,7 +3464,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3123
3464
|
}
|
|
3124
3465
|
keysToRemove.forEach((key) => sessionStorage.removeItem(key));
|
|
3125
3466
|
} catch (error) {
|
|
3126
|
-
|
|
3467
|
+
logger20.error("Failed to clear query results from sessionStorage", { error });
|
|
3127
3468
|
}
|
|
3128
3469
|
}
|
|
3129
3470
|
// CacheMapMetadataProvider implementation
|
|
@@ -3170,7 +3511,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3170
3511
|
}
|
|
3171
3512
|
return metadata;
|
|
3172
3513
|
} catch (error) {
|
|
3173
|
-
|
|
3514
|
+
logger20.error("Error getting all metadata from sessionStorage", { error });
|
|
3174
3515
|
return metadata;
|
|
3175
3516
|
}
|
|
3176
3517
|
}
|
|
@@ -3190,7 +3531,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3190
3531
|
}
|
|
3191
3532
|
// Invalidation methods
|
|
3192
3533
|
async invalidateItemKeys(keys) {
|
|
3193
|
-
|
|
3534
|
+
logger20.debug("invalidateItemKeys", { keys });
|
|
3194
3535
|
if (keys.length === 0) {
|
|
3195
3536
|
return;
|
|
3196
3537
|
}
|
|
@@ -3234,24 +3575,24 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3234
3575
|
}
|
|
3235
3576
|
}
|
|
3236
3577
|
} catch (error) {
|
|
3237
|
-
|
|
3578
|
+
logger20.debug("Failed to parse query result", { queryKey, error });
|
|
3238
3579
|
}
|
|
3239
3580
|
}
|
|
3240
3581
|
queriesToRemove.forEach((queryKey) => {
|
|
3241
3582
|
sessionStorage.removeItem(queryKey);
|
|
3242
3583
|
});
|
|
3243
|
-
|
|
3584
|
+
logger20.debug("Selectively invalidated queries referencing affected keys", {
|
|
3244
3585
|
affectedKeys: keys.length,
|
|
3245
3586
|
queriesRemoved: queriesToRemove.length,
|
|
3246
3587
|
totalQueries: queryKeys.length
|
|
3247
3588
|
});
|
|
3248
3589
|
} catch (error) {
|
|
3249
|
-
|
|
3590
|
+
logger20.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
3250
3591
|
await this.clearQueryResults();
|
|
3251
3592
|
}
|
|
3252
3593
|
}
|
|
3253
3594
|
async invalidateLocation(locations) {
|
|
3254
|
-
|
|
3595
|
+
logger20.debug("invalidateLocation", { locations });
|
|
3255
3596
|
let keysToInvalidate = [];
|
|
3256
3597
|
if (locations.length === 0) {
|
|
3257
3598
|
const allKeys = await this.keys();
|
|
@@ -3317,7 +3658,7 @@ import {
|
|
|
3317
3658
|
isQueryMatch as isQueryMatch5
|
|
3318
3659
|
} from "@fjell/core";
|
|
3319
3660
|
import safeStringify3 from "fast-safe-stringify";
|
|
3320
|
-
var
|
|
3661
|
+
var logger21 = logger_default.get("AsyncIndexDBCacheMap");
|
|
3321
3662
|
var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
3322
3663
|
types;
|
|
3323
3664
|
dbName;
|
|
@@ -3343,19 +3684,19 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3343
3684
|
}
|
|
3344
3685
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3345
3686
|
request.onerror = () => {
|
|
3346
|
-
|
|
3687
|
+
logger21.error("Error opening IndexedDB", { error: request.error });
|
|
3347
3688
|
reject(request.error);
|
|
3348
3689
|
};
|
|
3349
3690
|
request.onsuccess = () => {
|
|
3350
|
-
|
|
3691
|
+
logger21.debug("IndexedDB opened successfully");
|
|
3351
3692
|
resolve(request.result);
|
|
3352
3693
|
};
|
|
3353
3694
|
request.onupgradeneeded = (event) => {
|
|
3354
|
-
|
|
3695
|
+
logger21.debug("IndexedDB upgrade needed");
|
|
3355
3696
|
const db = event.target.result;
|
|
3356
3697
|
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
3357
3698
|
db.createObjectStore(this.storeName);
|
|
3358
|
-
|
|
3699
|
+
logger21.debug("Created object store", { storeName: this.storeName });
|
|
3359
3700
|
}
|
|
3360
3701
|
};
|
|
3361
3702
|
});
|
|
@@ -3366,7 +3707,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3366
3707
|
return this.normalizedHashFunction(key);
|
|
3367
3708
|
}
|
|
3368
3709
|
async get(key) {
|
|
3369
|
-
|
|
3710
|
+
logger21.trace("get", { key });
|
|
3370
3711
|
try {
|
|
3371
3712
|
const db = await this.getDB();
|
|
3372
3713
|
const transaction = db.transaction([this.storeName], "readonly");
|
|
@@ -3375,7 +3716,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3375
3716
|
return new Promise((resolve, reject) => {
|
|
3376
3717
|
const request = store.get(storageKey);
|
|
3377
3718
|
request.onerror = () => {
|
|
3378
|
-
|
|
3719
|
+
logger21.error("Error getting from IndexedDB", { key, error: request.error });
|
|
3379
3720
|
reject(request.error);
|
|
3380
3721
|
};
|
|
3381
3722
|
request.onsuccess = () => {
|
|
@@ -3388,7 +3729,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3388
3729
|
};
|
|
3389
3730
|
});
|
|
3390
3731
|
} catch (error) {
|
|
3391
|
-
|
|
3732
|
+
logger21.error("Error in IndexedDB get operation", { key, error });
|
|
3392
3733
|
return null;
|
|
3393
3734
|
}
|
|
3394
3735
|
}
|
|
@@ -3396,7 +3737,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3396
3737
|
* Get both the value and metadata for an item
|
|
3397
3738
|
*/
|
|
3398
3739
|
async getWithMetadata(key) {
|
|
3399
|
-
|
|
3740
|
+
logger21.trace("getWithMetadata", { key });
|
|
3400
3741
|
try {
|
|
3401
3742
|
const db = await this.getDB();
|
|
3402
3743
|
const transaction = db.transaction([this.storeName], "readonly");
|
|
@@ -3405,7 +3746,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3405
3746
|
return new Promise((resolve, reject) => {
|
|
3406
3747
|
const request = store.get(storageKey);
|
|
3407
3748
|
request.onerror = () => {
|
|
3408
|
-
|
|
3749
|
+
logger21.error("Error getting from IndexedDB", { key, error: request.error });
|
|
3409
3750
|
reject(request.error);
|
|
3410
3751
|
};
|
|
3411
3752
|
request.onsuccess = () => {
|
|
@@ -3421,12 +3762,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3421
3762
|
};
|
|
3422
3763
|
});
|
|
3423
3764
|
} catch (error) {
|
|
3424
|
-
|
|
3765
|
+
logger21.error("Error in IndexedDB getWithMetadata operation", { key, error });
|
|
3425
3766
|
return null;
|
|
3426
3767
|
}
|
|
3427
3768
|
}
|
|
3428
3769
|
async set(key, value, metadata) {
|
|
3429
|
-
|
|
3770
|
+
logger21.trace("set", { key, value, hasMetadata: !!metadata });
|
|
3430
3771
|
try {
|
|
3431
3772
|
const db = await this.getDB();
|
|
3432
3773
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3441,7 +3782,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3441
3782
|
return new Promise((resolve, reject) => {
|
|
3442
3783
|
const request = store.put(storedItem, storageKey);
|
|
3443
3784
|
request.onerror = () => {
|
|
3444
|
-
|
|
3785
|
+
logger21.error("Error setting in IndexedDB", { key, value, error: request.error });
|
|
3445
3786
|
reject(request.error);
|
|
3446
3787
|
};
|
|
3447
3788
|
request.onsuccess = () => {
|
|
@@ -3449,7 +3790,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3449
3790
|
};
|
|
3450
3791
|
});
|
|
3451
3792
|
} catch (error) {
|
|
3452
|
-
|
|
3793
|
+
logger21.error("Error in IndexedDB set operation", { key, value, error });
|
|
3453
3794
|
throw new Error(`Failed to store item in IndexedDB: ${error}`);
|
|
3454
3795
|
}
|
|
3455
3796
|
}
|
|
@@ -3457,16 +3798,16 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3457
3798
|
* Update only the metadata for an existing item
|
|
3458
3799
|
*/
|
|
3459
3800
|
async setMetadata(key, metadata) {
|
|
3460
|
-
|
|
3801
|
+
logger21.trace("setMetadata", { key, metadata });
|
|
3461
3802
|
try {
|
|
3462
3803
|
const existing = await this.getWithMetadata(key);
|
|
3463
3804
|
if (existing) {
|
|
3464
3805
|
await this.set(key, existing.value, metadata);
|
|
3465
3806
|
} else {
|
|
3466
|
-
|
|
3807
|
+
logger21.warning("Attempted to set metadata for non-existent item", { key });
|
|
3467
3808
|
}
|
|
3468
3809
|
} catch (error) {
|
|
3469
|
-
|
|
3810
|
+
logger21.error("Error in IndexedDB setMetadata operation", { key, error });
|
|
3470
3811
|
throw new Error(`Failed to update metadata in IndexedDB: ${error}`);
|
|
3471
3812
|
}
|
|
3472
3813
|
}
|
|
@@ -3479,7 +3820,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3479
3820
|
return new Promise((resolve, reject) => {
|
|
3480
3821
|
const request = store.get(storageKey);
|
|
3481
3822
|
request.onerror = () => {
|
|
3482
|
-
|
|
3823
|
+
logger21.error("Error checking key in IndexedDB", { key, error: request.error });
|
|
3483
3824
|
reject(request.error);
|
|
3484
3825
|
};
|
|
3485
3826
|
request.onsuccess = () => {
|
|
@@ -3493,12 +3834,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3493
3834
|
};
|
|
3494
3835
|
});
|
|
3495
3836
|
} catch (error) {
|
|
3496
|
-
|
|
3837
|
+
logger21.error("Error in IndexedDB includesKey operation", { key, error });
|
|
3497
3838
|
return false;
|
|
3498
3839
|
}
|
|
3499
3840
|
}
|
|
3500
3841
|
async delete(key) {
|
|
3501
|
-
|
|
3842
|
+
logger21.trace("delete", { key });
|
|
3502
3843
|
try {
|
|
3503
3844
|
const db = await this.getDB();
|
|
3504
3845
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3507,7 +3848,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3507
3848
|
return new Promise((resolve, reject) => {
|
|
3508
3849
|
const request = store.delete(storageKey);
|
|
3509
3850
|
request.onerror = () => {
|
|
3510
|
-
|
|
3851
|
+
logger21.error("Error deleting from IndexedDB", { key, error: request.error });
|
|
3511
3852
|
reject(request.error);
|
|
3512
3853
|
};
|
|
3513
3854
|
request.onsuccess = () => {
|
|
@@ -3515,22 +3856,22 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3515
3856
|
};
|
|
3516
3857
|
});
|
|
3517
3858
|
} catch (error) {
|
|
3518
|
-
|
|
3859
|
+
logger21.error("Error in IndexedDB delete operation", { key, error });
|
|
3519
3860
|
}
|
|
3520
3861
|
}
|
|
3521
3862
|
async allIn(locations) {
|
|
3522
3863
|
const allKeys = await this.keys();
|
|
3523
3864
|
if (locations.length === 0) {
|
|
3524
|
-
|
|
3865
|
+
logger21.debug("Returning all items, LocKeys is empty");
|
|
3525
3866
|
const promises = allKeys.map((key) => this.get(key));
|
|
3526
3867
|
const results = await Promise.all(promises);
|
|
3527
3868
|
return results.filter((item) => item !== null);
|
|
3528
3869
|
} else {
|
|
3529
3870
|
const locKeys = locations;
|
|
3530
|
-
|
|
3871
|
+
logger21.debug("allIn", { locKeys, keys: allKeys.length });
|
|
3531
3872
|
const filteredKeys = allKeys.filter((key) => key && isComKey5(key)).filter((key) => {
|
|
3532
3873
|
const ComKey16 = key;
|
|
3533
|
-
|
|
3874
|
+
logger21.debug("Comparing Location Keys", {
|
|
3534
3875
|
locKeys,
|
|
3535
3876
|
ComKey: ComKey16
|
|
3536
3877
|
});
|
|
@@ -3542,12 +3883,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3542
3883
|
}
|
|
3543
3884
|
}
|
|
3544
3885
|
async contains(query, locations) {
|
|
3545
|
-
|
|
3886
|
+
logger21.debug("contains", { query, locations });
|
|
3546
3887
|
const items = await this.allIn(locations);
|
|
3547
3888
|
return items.some((item) => isQueryMatch5(item, query));
|
|
3548
3889
|
}
|
|
3549
3890
|
async queryIn(query, locations = []) {
|
|
3550
|
-
|
|
3891
|
+
logger21.debug("queryIn", { query, locations });
|
|
3551
3892
|
const items = await this.allIn(locations);
|
|
3552
3893
|
return items.filter((item) => isQueryMatch5(item, query));
|
|
3553
3894
|
}
|
|
@@ -3563,7 +3904,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3563
3904
|
return new Promise((resolve, reject) => {
|
|
3564
3905
|
const request = store.openCursor();
|
|
3565
3906
|
request.onerror = () => {
|
|
3566
|
-
|
|
3907
|
+
logger21.error("Error getting keys from IndexedDB", { error: request.error });
|
|
3567
3908
|
reject(request.error);
|
|
3568
3909
|
};
|
|
3569
3910
|
request.onsuccess = (event) => {
|
|
@@ -3578,7 +3919,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3578
3919
|
};
|
|
3579
3920
|
});
|
|
3580
3921
|
} catch (error) {
|
|
3581
|
-
|
|
3922
|
+
logger21.error("Error in IndexedDB keys operation", { error });
|
|
3582
3923
|
return [];
|
|
3583
3924
|
}
|
|
3584
3925
|
}
|
|
@@ -3594,7 +3935,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3594
3935
|
return new Promise((resolve, reject) => {
|
|
3595
3936
|
const request = store.openCursor();
|
|
3596
3937
|
request.onerror = () => {
|
|
3597
|
-
|
|
3938
|
+
logger21.error("Error getting metadata from IndexedDB", { error: request.error });
|
|
3598
3939
|
reject(request.error);
|
|
3599
3940
|
};
|
|
3600
3941
|
request.onsuccess = (event) => {
|
|
@@ -3612,7 +3953,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3612
3953
|
};
|
|
3613
3954
|
});
|
|
3614
3955
|
} catch (error) {
|
|
3615
|
-
|
|
3956
|
+
logger21.error("Error in IndexedDB getAllMetadata operation", { error });
|
|
3616
3957
|
return metadataMap;
|
|
3617
3958
|
}
|
|
3618
3959
|
}
|
|
@@ -3625,7 +3966,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3625
3966
|
return new Promise((resolve, reject) => {
|
|
3626
3967
|
const request = store.openCursor();
|
|
3627
3968
|
request.onerror = () => {
|
|
3628
|
-
|
|
3969
|
+
logger21.error("Error getting values from IndexedDB", { error: request.error });
|
|
3629
3970
|
reject(request.error);
|
|
3630
3971
|
};
|
|
3631
3972
|
request.onsuccess = (event) => {
|
|
@@ -3640,12 +3981,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3640
3981
|
};
|
|
3641
3982
|
});
|
|
3642
3983
|
} catch (error) {
|
|
3643
|
-
|
|
3984
|
+
logger21.error("Error in IndexedDB values operation", { error });
|
|
3644
3985
|
return [];
|
|
3645
3986
|
}
|
|
3646
3987
|
}
|
|
3647
3988
|
async clear() {
|
|
3648
|
-
|
|
3989
|
+
logger21.debug("Clearing IndexedDB cache");
|
|
3649
3990
|
try {
|
|
3650
3991
|
const db = await this.getDB();
|
|
3651
3992
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3653,7 +3994,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3653
3994
|
return new Promise((resolve, reject) => {
|
|
3654
3995
|
const request = store.clear();
|
|
3655
3996
|
request.onerror = () => {
|
|
3656
|
-
|
|
3997
|
+
logger21.error("Error clearing IndexedDB cache", { error: request.error });
|
|
3657
3998
|
reject(request.error);
|
|
3658
3999
|
};
|
|
3659
4000
|
request.onsuccess = () => {
|
|
@@ -3661,17 +4002,17 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3661
4002
|
};
|
|
3662
4003
|
});
|
|
3663
4004
|
} catch (error) {
|
|
3664
|
-
|
|
4005
|
+
logger21.error("Error in IndexedDB clear operation", { error });
|
|
3665
4006
|
}
|
|
3666
4007
|
}
|
|
3667
4008
|
// Async Query result caching methods
|
|
3668
4009
|
async setQueryResult(queryHash, itemKeys) {
|
|
3669
|
-
|
|
4010
|
+
logger21.trace("setQueryResult", { queryHash, itemKeys });
|
|
3670
4011
|
try {
|
|
3671
4012
|
return new Promise((resolve, reject) => {
|
|
3672
4013
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3673
4014
|
request.onerror = () => {
|
|
3674
|
-
|
|
4015
|
+
logger21.error("Failed to open database for setQueryResult", { error: request.error });
|
|
3675
4016
|
reject(request.error);
|
|
3676
4017
|
};
|
|
3677
4018
|
request.onsuccess = () => {
|
|
@@ -3684,7 +4025,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3684
4025
|
const queryKey = `query:${queryHash}`;
|
|
3685
4026
|
const putRequest = store.put(safeStringify3(entry), queryKey);
|
|
3686
4027
|
putRequest.onerror = () => {
|
|
3687
|
-
|
|
4028
|
+
logger21.error("Failed to store query result", { queryHash, error: putRequest.error });
|
|
3688
4029
|
reject(putRequest.error);
|
|
3689
4030
|
};
|
|
3690
4031
|
putRequest.onsuccess = () => {
|
|
@@ -3693,17 +4034,17 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3693
4034
|
};
|
|
3694
4035
|
});
|
|
3695
4036
|
} catch (error) {
|
|
3696
|
-
|
|
4037
|
+
logger21.error("Error in setQueryResult", { queryHash, error });
|
|
3697
4038
|
throw error;
|
|
3698
4039
|
}
|
|
3699
4040
|
}
|
|
3700
4041
|
async getQueryResult(queryHash) {
|
|
3701
|
-
|
|
4042
|
+
logger21.trace("getQueryResult", { queryHash });
|
|
3702
4043
|
try {
|
|
3703
4044
|
return new Promise((resolve, reject) => {
|
|
3704
4045
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3705
4046
|
request.onerror = () => {
|
|
3706
|
-
|
|
4047
|
+
logger21.error("Failed to open database for getQueryResult", { error: request.error });
|
|
3707
4048
|
reject(request.error);
|
|
3708
4049
|
};
|
|
3709
4050
|
request.onsuccess = () => {
|
|
@@ -3713,7 +4054,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3713
4054
|
const queryKey = `query:${queryHash}`;
|
|
3714
4055
|
const getRequest = store.get(queryKey);
|
|
3715
4056
|
getRequest.onerror = () => {
|
|
3716
|
-
|
|
4057
|
+
logger21.error("Failed to retrieve query result", { queryHash, error: getRequest.error });
|
|
3717
4058
|
reject(getRequest.error);
|
|
3718
4059
|
};
|
|
3719
4060
|
getRequest.onsuccess = () => {
|
|
@@ -3730,34 +4071,34 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3730
4071
|
}
|
|
3731
4072
|
resolve(entry.itemKeys || null);
|
|
3732
4073
|
} catch (parseError) {
|
|
3733
|
-
|
|
4074
|
+
logger21.error("Failed to parse query result", { queryHash, error: parseError });
|
|
3734
4075
|
resolve(null);
|
|
3735
4076
|
}
|
|
3736
4077
|
};
|
|
3737
4078
|
};
|
|
3738
4079
|
});
|
|
3739
4080
|
} catch (error) {
|
|
3740
|
-
|
|
4081
|
+
logger21.error("Error in getQueryResult", { queryHash, error });
|
|
3741
4082
|
return null;
|
|
3742
4083
|
}
|
|
3743
4084
|
}
|
|
3744
4085
|
async hasQueryResult(queryHash) {
|
|
3745
|
-
|
|
4086
|
+
logger21.trace("hasQueryResult", { queryHash });
|
|
3746
4087
|
try {
|
|
3747
4088
|
const result = await this.getQueryResult(queryHash);
|
|
3748
4089
|
return result !== null;
|
|
3749
4090
|
} catch (error) {
|
|
3750
|
-
|
|
4091
|
+
logger21.error("Error in hasQueryResult", { queryHash, error });
|
|
3751
4092
|
return false;
|
|
3752
4093
|
}
|
|
3753
4094
|
}
|
|
3754
4095
|
async deleteQueryResult(queryHash) {
|
|
3755
|
-
|
|
4096
|
+
logger21.trace("deleteQueryResult", { queryHash });
|
|
3756
4097
|
try {
|
|
3757
4098
|
return new Promise((resolve, reject) => {
|
|
3758
4099
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3759
4100
|
request.onerror = () => {
|
|
3760
|
-
|
|
4101
|
+
logger21.error("Failed to open database for deleteQueryResult", { error: request.error });
|
|
3761
4102
|
reject(request.error);
|
|
3762
4103
|
};
|
|
3763
4104
|
request.onsuccess = () => {
|
|
@@ -3767,7 +4108,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3767
4108
|
const queryKey = `query:${queryHash}`;
|
|
3768
4109
|
const deleteRequest = store.delete(queryKey);
|
|
3769
4110
|
deleteRequest.onerror = () => {
|
|
3770
|
-
|
|
4111
|
+
logger21.error("Failed to delete query result", { queryHash, error: deleteRequest.error });
|
|
3771
4112
|
reject(deleteRequest.error);
|
|
3772
4113
|
};
|
|
3773
4114
|
deleteRequest.onsuccess = () => {
|
|
@@ -3776,12 +4117,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3776
4117
|
};
|
|
3777
4118
|
});
|
|
3778
4119
|
} catch (error) {
|
|
3779
|
-
|
|
4120
|
+
logger21.error("Error in deleteQueryResult", { queryHash, error });
|
|
3780
4121
|
throw error;
|
|
3781
4122
|
}
|
|
3782
4123
|
}
|
|
3783
4124
|
async invalidateItemKeys(keys) {
|
|
3784
|
-
|
|
4125
|
+
logger21.debug("invalidateItemKeys", { keys });
|
|
3785
4126
|
if (keys.length === 0) {
|
|
3786
4127
|
return;
|
|
3787
4128
|
}
|
|
@@ -3818,7 +4159,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3818
4159
|
queryResults2[queryHash] = itemKeys;
|
|
3819
4160
|
}
|
|
3820
4161
|
} catch (error) {
|
|
3821
|
-
|
|
4162
|
+
logger21.debug("Failed to parse query result", { key: item.key, error });
|
|
3822
4163
|
}
|
|
3823
4164
|
}
|
|
3824
4165
|
}
|
|
@@ -3846,18 +4187,18 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3846
4187
|
});
|
|
3847
4188
|
}
|
|
3848
4189
|
}
|
|
3849
|
-
|
|
4190
|
+
logger21.debug("Selectively invalidated queries referencing affected keys", {
|
|
3850
4191
|
affectedKeys: keys.length,
|
|
3851
4192
|
queriesRemoved: queriesToRemove.length,
|
|
3852
4193
|
totalQueries: Object.keys(queryResults).length
|
|
3853
4194
|
});
|
|
3854
4195
|
} catch (error) {
|
|
3855
|
-
|
|
4196
|
+
logger21.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
3856
4197
|
await this.clearQueryResults();
|
|
3857
4198
|
}
|
|
3858
4199
|
}
|
|
3859
4200
|
async invalidateLocation(locations) {
|
|
3860
|
-
|
|
4201
|
+
logger21.debug("invalidateLocation", { locations });
|
|
3861
4202
|
let keysToInvalidate = [];
|
|
3862
4203
|
if (locations.length === 0) {
|
|
3863
4204
|
await this.clearQueryResults();
|
|
@@ -3870,12 +4211,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3870
4211
|
}
|
|
3871
4212
|
}
|
|
3872
4213
|
async clearQueryResults() {
|
|
3873
|
-
|
|
4214
|
+
logger21.trace("clearQueryResults");
|
|
3874
4215
|
try {
|
|
3875
4216
|
return new Promise((resolve, reject) => {
|
|
3876
4217
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3877
4218
|
request.onerror = () => {
|
|
3878
|
-
|
|
4219
|
+
logger21.error("Failed to open database for clearQueryResults", { error: request.error });
|
|
3879
4220
|
reject(request.error);
|
|
3880
4221
|
};
|
|
3881
4222
|
request.onsuccess = () => {
|
|
@@ -3885,7 +4226,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3885
4226
|
const cursorRequest = store.openCursor();
|
|
3886
4227
|
const keysToDelete = [];
|
|
3887
4228
|
cursorRequest.onerror = () => {
|
|
3888
|
-
|
|
4229
|
+
logger21.error("Failed to open cursor for clearQueryResults", { error: cursorRequest.error });
|
|
3889
4230
|
reject(cursorRequest.error);
|
|
3890
4231
|
};
|
|
3891
4232
|
cursorRequest.onsuccess = () => {
|
|
@@ -3906,7 +4247,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3906
4247
|
keysToDelete.forEach((queryKey) => {
|
|
3907
4248
|
const deleteRequest = store.delete(queryKey);
|
|
3908
4249
|
deleteRequest.onerror = () => {
|
|
3909
|
-
|
|
4250
|
+
logger21.error("Failed to delete query key", { queryKey, error: deleteRequest.error });
|
|
3910
4251
|
deletedCount++;
|
|
3911
4252
|
if (deletedCount === totalToDelete) {
|
|
3912
4253
|
resolve();
|
|
@@ -3924,14 +4265,14 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3924
4265
|
};
|
|
3925
4266
|
});
|
|
3926
4267
|
} catch (error) {
|
|
3927
|
-
|
|
4268
|
+
logger21.error("Error in clearQueryResults", { error });
|
|
3928
4269
|
throw error;
|
|
3929
4270
|
}
|
|
3930
4271
|
}
|
|
3931
4272
|
};
|
|
3932
4273
|
|
|
3933
4274
|
// src/browser/IndexDBCacheMap.ts
|
|
3934
|
-
var
|
|
4275
|
+
var logger22 = logger_default.get("IndexDBCacheMap");
|
|
3935
4276
|
var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
3936
4277
|
implementationType = "browser/indexedDB";
|
|
3937
4278
|
// Memory storage
|
|
@@ -4115,7 +4456,7 @@ var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
|
4115
4456
|
}
|
|
4116
4457
|
// Invalidation methods
|
|
4117
4458
|
async invalidateItemKeys(keys) {
|
|
4118
|
-
|
|
4459
|
+
logger22.debug("invalidateItemKeys", { keys });
|
|
4119
4460
|
if (keys.length === 0) {
|
|
4120
4461
|
return;
|
|
4121
4462
|
}
|
|
@@ -4145,7 +4486,7 @@ var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
|
4145
4486
|
queriesToRemove.forEach((queryHash) => {
|
|
4146
4487
|
delete this.queryResultCache[queryHash];
|
|
4147
4488
|
});
|
|
4148
|
-
|
|
4489
|
+
logger22.debug("Selectively invalidated queries referencing affected keys", {
|
|
4149
4490
|
affectedKeys: keys.length,
|
|
4150
4491
|
queriesRemoved: queriesToRemove.length,
|
|
4151
4492
|
totalQueries: Object.keys(this.queryResultCache).length
|
|
@@ -4279,6 +4620,7 @@ var createOptions = (cacheOptions) => {
|
|
|
4279
4620
|
return result;
|
|
4280
4621
|
};
|
|
4281
4622
|
var createCacheMap = (kta, options) => {
|
|
4623
|
+
let underlyingCache;
|
|
4282
4624
|
switch (options.cacheType) {
|
|
4283
4625
|
case "memory":
|
|
4284
4626
|
if (options.memoryConfig?.size && (options.memoryConfig.size.maxSizeBytes || options.memoryConfig.size.maxItems)) {
|
|
@@ -4286,37 +4628,47 @@ var createCacheMap = (kta, options) => {
|
|
|
4286
4628
|
maxSizeBytes: options.memoryConfig.size.maxSizeBytes,
|
|
4287
4629
|
maxItems: options.memoryConfig.size.maxItems
|
|
4288
4630
|
};
|
|
4289
|
-
|
|
4631
|
+
underlyingCache = new EnhancedMemoryCacheMap(
|
|
4290
4632
|
kta,
|
|
4291
4633
|
sizeConfig
|
|
4292
4634
|
);
|
|
4635
|
+
} else {
|
|
4636
|
+
underlyingCache = new MemoryCacheMap(kta);
|
|
4293
4637
|
}
|
|
4294
|
-
|
|
4638
|
+
break;
|
|
4295
4639
|
case "localStorage":
|
|
4296
|
-
|
|
4640
|
+
underlyingCache = new LocalStorageCacheMap(
|
|
4297
4641
|
kta,
|
|
4298
4642
|
options.webStorageConfig?.keyPrefix
|
|
4299
4643
|
);
|
|
4644
|
+
break;
|
|
4300
4645
|
case "sessionStorage":
|
|
4301
|
-
|
|
4646
|
+
underlyingCache = new SessionStorageCacheMap(
|
|
4302
4647
|
kta,
|
|
4303
4648
|
options.webStorageConfig?.keyPrefix
|
|
4304
4649
|
);
|
|
4650
|
+
break;
|
|
4305
4651
|
case "indexedDB":
|
|
4306
|
-
|
|
4652
|
+
underlyingCache = new IndexDBCacheMap(
|
|
4307
4653
|
kta,
|
|
4308
4654
|
options.indexedDBConfig?.dbName,
|
|
4309
4655
|
options.indexedDBConfig?.storeName,
|
|
4310
4656
|
options.indexedDBConfig?.version
|
|
4311
4657
|
);
|
|
4658
|
+
break;
|
|
4312
4659
|
case "custom":
|
|
4313
4660
|
if (!options.customCacheMapFactory) {
|
|
4314
4661
|
throw new Error('Custom cache map factory is required when cacheType is "custom"');
|
|
4315
4662
|
}
|
|
4316
|
-
|
|
4663
|
+
underlyingCache = options.customCacheMapFactory(kta);
|
|
4664
|
+
break;
|
|
4317
4665
|
default:
|
|
4318
4666
|
throw new Error(`Unsupported cache type: ${options.cacheType}`);
|
|
4319
4667
|
}
|
|
4668
|
+
if (options.twoLayer && Object.keys(options.twoLayer).length > 0) {
|
|
4669
|
+
return new TwoLayerCacheMap(underlyingCache, options.twoLayer);
|
|
4670
|
+
}
|
|
4671
|
+
return underlyingCache;
|
|
4320
4672
|
};
|
|
4321
4673
|
var validateOptions = (options) => {
|
|
4322
4674
|
const validProperties = /* @__PURE__ */ new Set([
|
|
@@ -4333,7 +4685,9 @@ var validateOptions = (options) => {
|
|
|
4333
4685
|
"webStorageConfig",
|
|
4334
4686
|
"memoryConfig",
|
|
4335
4687
|
"customCacheMapFactory",
|
|
4336
|
-
"evictionConfig"
|
|
4688
|
+
"evictionConfig",
|
|
4689
|
+
// Two-layer cache configuration
|
|
4690
|
+
"twoLayer"
|
|
4337
4691
|
]);
|
|
4338
4692
|
const unknownProperties = [];
|
|
4339
4693
|
const propertySuggestions = {
|
|
@@ -4526,41 +4880,213 @@ var reset = async (coordinate, options) => {
|
|
|
4526
4880
|
}
|
|
4527
4881
|
};
|
|
4528
4882
|
|
|
4529
|
-
// src/
|
|
4530
|
-
var
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4883
|
+
// src/ttl/TTLConfig.ts
|
|
4884
|
+
var defaultTTLConfig = {
|
|
4885
|
+
item: {
|
|
4886
|
+
default: 3600,
|
|
4887
|
+
// 1 hour for most items
|
|
4888
|
+
byType: {
|
|
4889
|
+
// Frequently changing data gets shorter TTL
|
|
4890
|
+
"orderPhase": 1800,
|
|
4891
|
+
// 30 minutes - order phases change often
|
|
4892
|
+
"orderStep": 1800,
|
|
4893
|
+
// 30 minutes - order steps change often
|
|
4894
|
+
"orderStatus": 900,
|
|
4895
|
+
// 15 minutes - status changes frequently
|
|
4896
|
+
// Relatively static data gets longer TTL
|
|
4897
|
+
"customer": 7200,
|
|
4898
|
+
// 2 hours - customer data changes rarely
|
|
4899
|
+
"user": 7200,
|
|
4900
|
+
// 2 hours - user data changes rarely
|
|
4901
|
+
"product": 14400,
|
|
4902
|
+
// 4 hours - product data very stable
|
|
4903
|
+
"category": 21600
|
|
4904
|
+
// 6 hours - categories almost never change
|
|
4905
|
+
}
|
|
4906
|
+
},
|
|
4907
|
+
query: {
|
|
4908
|
+
complete: 300,
|
|
4909
|
+
// 5 minutes for complete queries
|
|
4910
|
+
faceted: 60,
|
|
4911
|
+
// 1 minute for filtered queries
|
|
4912
|
+
byFacet: {
|
|
4913
|
+
"report": 30,
|
|
4914
|
+
// 30 seconds - reports need fresh data
|
|
4915
|
+
"search": 120,
|
|
4916
|
+
// 2 minutes - search results can be cached longer
|
|
4917
|
+
"dashboard": 45,
|
|
4918
|
+
// 45 seconds - dashboards need recent data
|
|
4919
|
+
"analytics": 180,
|
|
4920
|
+
// 3 minutes - analytics can be slightly stale
|
|
4921
|
+
"export": 15
|
|
4922
|
+
// 15 seconds - exports need fresh data
|
|
4923
|
+
}
|
|
4924
|
+
},
|
|
4925
|
+
adjustments: {
|
|
4926
|
+
peakHours: {
|
|
4927
|
+
start: 9,
|
|
4928
|
+
// 9 AM
|
|
4929
|
+
end: 17,
|
|
4930
|
+
// 5 PM
|
|
4931
|
+
multiplier: 0.5
|
|
4932
|
+
// Half TTL during business hours for fresher data
|
|
4538
4933
|
},
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4934
|
+
staleWhileRevalidate: true,
|
|
4935
|
+
timezone: "system"
|
|
4936
|
+
// Use system timezone
|
|
4937
|
+
},
|
|
4938
|
+
warming: {
|
|
4939
|
+
enabled: false,
|
|
4940
|
+
// Disabled by default, enable per use case
|
|
4941
|
+
interval: 3e5,
|
|
4942
|
+
// 5 minutes
|
|
4943
|
+
queries: [
|
|
4944
|
+
// Common queries to warm - customize per application
|
|
4945
|
+
{ params: { limit: 20, status: "active" }, priority: 1 },
|
|
4946
|
+
{ params: { limit: 50, recent: true }, priority: 2 }
|
|
4947
|
+
]
|
|
4948
|
+
}
|
|
4949
|
+
};
|
|
4950
|
+
var highTrafficTTLConfig = {
|
|
4951
|
+
...defaultTTLConfig,
|
|
4952
|
+
query: {
|
|
4953
|
+
complete: 180,
|
|
4954
|
+
// 3 minutes (shorter for high traffic)
|
|
4955
|
+
faceted: 30,
|
|
4956
|
+
// 30 seconds
|
|
4957
|
+
byFacet: {
|
|
4958
|
+
"report": 15,
|
|
4959
|
+
// 15 seconds
|
|
4960
|
+
"search": 60,
|
|
4961
|
+
// 1 minute
|
|
4962
|
+
"dashboard": 20,
|
|
4963
|
+
// 20 seconds
|
|
4964
|
+
"analytics": 90
|
|
4965
|
+
// 1.5 minutes
|
|
4966
|
+
}
|
|
4967
|
+
},
|
|
4968
|
+
adjustments: {
|
|
4969
|
+
peakHours: {
|
|
4970
|
+
start: 8,
|
|
4971
|
+
// Earlier peak
|
|
4972
|
+
end: 18,
|
|
4973
|
+
// Later peak
|
|
4974
|
+
multiplier: 0.3
|
|
4975
|
+
// Even shorter TTL during peaks
|
|
4550
4976
|
},
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4977
|
+
staleWhileRevalidate: true
|
|
4978
|
+
}
|
|
4979
|
+
};
|
|
4980
|
+
|
|
4981
|
+
// src/Operations.ts
|
|
4982
|
+
var logger23 = logger_default.get("Operations");
|
|
4983
|
+
var CacheMapOperations = class {
|
|
4984
|
+
constructor(api, coordinate, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry) {
|
|
4985
|
+
this.api = api;
|
|
4986
|
+
this.coordinate = coordinate;
|
|
4987
|
+
this.cacheMap = cacheMap;
|
|
4988
|
+
this.pkType = pkType;
|
|
4989
|
+
this.options = options;
|
|
4990
|
+
this.eventEmitter = eventEmitter;
|
|
4991
|
+
this.ttlManager = ttlManager;
|
|
4992
|
+
this.evictionManager = evictionManager;
|
|
4993
|
+
this.statsManager = statsManager;
|
|
4994
|
+
this.registry = registry;
|
|
4995
|
+
if (this.options.enableDebugLogging) {
|
|
4996
|
+
logger23.debug("CacheMapOperations initialized", {
|
|
4997
|
+
cacheType: this.cacheMap.implementationType,
|
|
4998
|
+
isTwoLayer: this.cacheMap instanceof TwoLayerCacheMap
|
|
4999
|
+
});
|
|
5000
|
+
}
|
|
5001
|
+
}
|
|
5002
|
+
// Create the cache context once and reuse it across all operations
|
|
5003
|
+
get context() {
|
|
5004
|
+
return createCacheContext(
|
|
5005
|
+
this.api,
|
|
5006
|
+
this.cacheMap,
|
|
5007
|
+
this.pkType,
|
|
5008
|
+
this.options,
|
|
5009
|
+
this.eventEmitter,
|
|
5010
|
+
this.ttlManager,
|
|
5011
|
+
this.evictionManager,
|
|
5012
|
+
this.statsManager,
|
|
5013
|
+
this.registry,
|
|
5014
|
+
this.coordinate
|
|
5015
|
+
);
|
|
5016
|
+
}
|
|
5017
|
+
async all(query = {}, locations = []) {
|
|
5018
|
+
return all(query, locations, this.context).then(([ctx, result]) => result);
|
|
5019
|
+
}
|
|
5020
|
+
async one(query = {}, locations = []) {
|
|
5021
|
+
return one(query, locations, this.context).then(([ctx, result]) => result);
|
|
5022
|
+
}
|
|
5023
|
+
async create(item, options) {
|
|
5024
|
+
const locations = options?.locations || [];
|
|
5025
|
+
return create(item, locations, this.context).then(([ctx, result]) => result);
|
|
5026
|
+
}
|
|
5027
|
+
async get(key) {
|
|
5028
|
+
return get(key, this.context).then(([ctx, result]) => result);
|
|
5029
|
+
}
|
|
5030
|
+
async retrieve(key) {
|
|
5031
|
+
return retrieve(key, this.context).then(([ctx, result]) => result);
|
|
5032
|
+
}
|
|
5033
|
+
async remove(key) {
|
|
5034
|
+
return remove(key, this.context).then((ctx) => void 0);
|
|
5035
|
+
}
|
|
5036
|
+
async update(key, item) {
|
|
5037
|
+
return update(key, item, this.context).then(([ctx, result]) => result);
|
|
5038
|
+
}
|
|
5039
|
+
async set(key, item) {
|
|
5040
|
+
return set(key, item, this.context).then(([ctx, result]) => result);
|
|
5041
|
+
}
|
|
5042
|
+
async reset() {
|
|
5043
|
+
await reset(this.coordinate, this.options);
|
|
5044
|
+
await this.cacheMap.clear();
|
|
5045
|
+
}
|
|
5046
|
+
async upsert(key, itemProperties, locations) {
|
|
5047
|
+
const existing = await this.get(key);
|
|
5048
|
+
if (existing) {
|
|
5049
|
+
return this.update(key, itemProperties);
|
|
5050
|
+
} else {
|
|
5051
|
+
return this.create(itemProperties, { locations: locations || [] });
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
5054
|
+
async action(key, actionName, body) {
|
|
5055
|
+
return action(key, actionName, body, this.context).then(([ctx, result, affectedItems]) => [result, affectedItems]);
|
|
5056
|
+
}
|
|
5057
|
+
async allAction(actionName, body, locations) {
|
|
5058
|
+
return allAction(actionName, body, locations, this.context).then(([ctx, result, affectedItems]) => [result, affectedItems]);
|
|
5059
|
+
}
|
|
5060
|
+
async facet(key, facetName, params) {
|
|
5061
|
+
return facet(key, facetName, params, this.context);
|
|
5062
|
+
}
|
|
5063
|
+
async allFacet(facetName, params, locations) {
|
|
5064
|
+
return allFacet(facetName, params, locations, this.context);
|
|
5065
|
+
}
|
|
5066
|
+
async find(finder, params, locations) {
|
|
5067
|
+
return find(finder, params, locations, this.context).then(([ctx, result]) => result);
|
|
5068
|
+
}
|
|
5069
|
+
async findOne(finder, params, locations) {
|
|
5070
|
+
return findOne(finder, params, locations, this.context).then(([ctx, result]) => result);
|
|
5071
|
+
}
|
|
5072
|
+
};
|
|
5073
|
+
var createOperations = (api, coordinate, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry) => {
|
|
5074
|
+
return new CacheMapOperations(
|
|
5075
|
+
api,
|
|
5076
|
+
coordinate,
|
|
5077
|
+
cacheMap,
|
|
5078
|
+
pkType,
|
|
5079
|
+
options,
|
|
5080
|
+
eventEmitter,
|
|
5081
|
+
ttlManager,
|
|
5082
|
+
evictionManager,
|
|
5083
|
+
statsManager,
|
|
5084
|
+
registry
|
|
5085
|
+
);
|
|
4560
5086
|
};
|
|
4561
5087
|
|
|
4562
5088
|
// src/eviction/EvictionManager.ts
|
|
4563
|
-
var
|
|
5089
|
+
var logger24 = logger_default.get("EvictionManager");
|
|
4564
5090
|
var EvictionManager = class {
|
|
4565
5091
|
evictionStrategy;
|
|
4566
5092
|
constructor(evictionStrategy) {
|
|
@@ -4572,7 +5098,7 @@ var EvictionManager = class {
|
|
|
4572
5098
|
*/
|
|
4573
5099
|
setEvictionStrategy(strategy) {
|
|
4574
5100
|
this.evictionStrategy = strategy;
|
|
4575
|
-
|
|
5101
|
+
logger24.debug("Eviction strategy updated", {
|
|
4576
5102
|
strategy: strategy?.getStrategyName() || "none"
|
|
4577
5103
|
});
|
|
4578
5104
|
}
|
|
@@ -4595,7 +5121,7 @@ var EvictionManager = class {
|
|
|
4595
5121
|
try {
|
|
4596
5122
|
await this.evictionStrategy.onItemAccessed(key, metadataProvider);
|
|
4597
5123
|
} catch (error) {
|
|
4598
|
-
|
|
5124
|
+
logger24.error("Error in eviction strategy onItemAccessed", { key, error });
|
|
4599
5125
|
}
|
|
4600
5126
|
}
|
|
4601
5127
|
/**
|
|
@@ -4620,14 +5146,14 @@ var EvictionManager = class {
|
|
|
4620
5146
|
}
|
|
4621
5147
|
await this.evictionStrategy.onItemAdded(key, estimatedSize, metadataProvider);
|
|
4622
5148
|
if (evictedKeys.length > 0) {
|
|
4623
|
-
|
|
5149
|
+
logger24.debug("Items evicted during addition", {
|
|
4624
5150
|
newKey: key,
|
|
4625
5151
|
evictedKeys,
|
|
4626
5152
|
strategy: this.evictionStrategy.getStrategyName()
|
|
4627
5153
|
});
|
|
4628
5154
|
}
|
|
4629
5155
|
} catch (error) {
|
|
4630
|
-
|
|
5156
|
+
logger24.error("Error in eviction strategy onItemAdded", { key, error });
|
|
4631
5157
|
}
|
|
4632
5158
|
return evictedKeys;
|
|
4633
5159
|
}
|
|
@@ -4643,7 +5169,7 @@ var EvictionManager = class {
|
|
|
4643
5169
|
try {
|
|
4644
5170
|
this.evictionStrategy.onItemRemoved(key, metadataProvider);
|
|
4645
5171
|
} catch (error) {
|
|
4646
|
-
|
|
5172
|
+
logger24.error("Error in eviction strategy onItemRemoved", { key, error });
|
|
4647
5173
|
}
|
|
4648
5174
|
}
|
|
4649
5175
|
/**
|
|
@@ -4664,13 +5190,13 @@ var EvictionManager = class {
|
|
|
4664
5190
|
evictedKeys.push(evictKey);
|
|
4665
5191
|
}
|
|
4666
5192
|
if (evictedKeys.length > 0) {
|
|
4667
|
-
|
|
5193
|
+
logger24.debug("Manual eviction performed", {
|
|
4668
5194
|
evictedKeys,
|
|
4669
5195
|
strategy: this.evictionStrategy.getStrategyName()
|
|
4670
5196
|
});
|
|
4671
5197
|
}
|
|
4672
5198
|
} catch (error) {
|
|
4673
|
-
|
|
5199
|
+
logger24.error("Error in manual eviction", { error });
|
|
4674
5200
|
}
|
|
4675
5201
|
return evictedKeys;
|
|
4676
5202
|
}
|
|
@@ -4690,7 +5216,7 @@ var EvictionManager = class {
|
|
|
4690
5216
|
this.evictionStrategy.reset();
|
|
4691
5217
|
}
|
|
4692
5218
|
}
|
|
4693
|
-
|
|
5219
|
+
logger24.debug("Eviction manager cleared");
|
|
4694
5220
|
}
|
|
4695
5221
|
/**
|
|
4696
5222
|
* Create eviction context from current cache state
|
|
@@ -6028,7 +6554,7 @@ function createEvictionStrategy(policy, maxCacheSize, config) {
|
|
|
6028
6554
|
}
|
|
6029
6555
|
|
|
6030
6556
|
// src/ttl/TTLManager.ts
|
|
6031
|
-
var
|
|
6557
|
+
var logger25 = logger_default.get("TTLManager");
|
|
6032
6558
|
var TTLManager = class {
|
|
6033
6559
|
config;
|
|
6034
6560
|
cleanupTimer;
|
|
@@ -6040,7 +6566,7 @@ var TTLManager = class {
|
|
|
6040
6566
|
validateOnAccess: true,
|
|
6041
6567
|
...config
|
|
6042
6568
|
};
|
|
6043
|
-
|
|
6569
|
+
logger25.debug("TTL_DEBUG: TTLManager created", {
|
|
6044
6570
|
config: this.config,
|
|
6045
6571
|
isTTLEnabled: this.isTTLEnabled(),
|
|
6046
6572
|
defaultTTL: this.config.defaultTTL
|
|
@@ -6073,13 +6599,13 @@ var TTLManager = class {
|
|
|
6073
6599
|
this.startAutoCleanup();
|
|
6074
6600
|
}
|
|
6075
6601
|
}
|
|
6076
|
-
|
|
6602
|
+
logger25.debug("TTL configuration updated", { config: this.config });
|
|
6077
6603
|
}
|
|
6078
6604
|
/**
|
|
6079
6605
|
* Set TTL metadata for an item when it's added
|
|
6080
6606
|
*/
|
|
6081
6607
|
async onItemAdded(key, metadataProvider, itemTTL) {
|
|
6082
|
-
|
|
6608
|
+
logger25.debug("TTL_DEBUG: onItemAdded called", {
|
|
6083
6609
|
key,
|
|
6084
6610
|
itemTTL,
|
|
6085
6611
|
isTTLEnabled: this.isTTLEnabled(),
|
|
@@ -6087,19 +6613,19 @@ var TTLManager = class {
|
|
|
6087
6613
|
metadataProviderType: metadataProvider?.constructor?.name
|
|
6088
6614
|
});
|
|
6089
6615
|
if (!this.isTTLEnabled() && !itemTTL) {
|
|
6090
|
-
|
|
6616
|
+
logger25.debug("TTL_DEBUG: No TTL configured for item - returning early", { key });
|
|
6091
6617
|
return;
|
|
6092
6618
|
}
|
|
6093
|
-
|
|
6619
|
+
logger25.debug("TTL_DEBUG: Getting metadata for key", { key });
|
|
6094
6620
|
const metadata = await metadataProvider.getMetadata(key);
|
|
6095
|
-
|
|
6621
|
+
logger25.debug("TTL_DEBUG: Retrieved metadata", {
|
|
6096
6622
|
key,
|
|
6097
6623
|
hasMetadata: !!metadata,
|
|
6098
6624
|
metadataKeys: metadata ? Object.keys(metadata) : null,
|
|
6099
6625
|
metadata
|
|
6100
6626
|
});
|
|
6101
6627
|
if (!metadata) {
|
|
6102
|
-
|
|
6628
|
+
logger25.warning("TTL_DEBUG: No metadata found for item when setting TTL", {
|
|
6103
6629
|
key,
|
|
6104
6630
|
metadataProviderType: metadataProvider?.constructor?.name,
|
|
6105
6631
|
metadataProviderMethods: metadataProvider ? Object.getOwnPropertyNames(Object.getPrototypeOf(metadataProvider)) : null
|
|
@@ -6107,7 +6633,7 @@ var TTLManager = class {
|
|
|
6107
6633
|
return;
|
|
6108
6634
|
}
|
|
6109
6635
|
const ttl = itemTTL || this.config.defaultTTL;
|
|
6110
|
-
|
|
6636
|
+
logger25.debug("TTL_DEBUG: Calculated TTL value", {
|
|
6111
6637
|
key,
|
|
6112
6638
|
itemTTL,
|
|
6113
6639
|
defaultTTL: this.config.defaultTTL,
|
|
@@ -6120,7 +6646,7 @@ var TTLManager = class {
|
|
|
6120
6646
|
expiresAt: metadata.addedAt + ttl,
|
|
6121
6647
|
ttl
|
|
6122
6648
|
};
|
|
6123
|
-
|
|
6649
|
+
logger25.debug("TTL_DEBUG: Setting TTL metadata", {
|
|
6124
6650
|
key,
|
|
6125
6651
|
ttl,
|
|
6126
6652
|
addedAt: metadata.addedAt,
|
|
@@ -6128,9 +6654,9 @@ var TTLManager = class {
|
|
|
6128
6654
|
ttlMetadata
|
|
6129
6655
|
});
|
|
6130
6656
|
await metadataProvider.setMetadata(key, ttlMetadata);
|
|
6131
|
-
|
|
6657
|
+
logger25.trace("TTL_DEBUG: TTL set for item", { key, ttl, expiresAt: ttlMetadata.expiresAt });
|
|
6132
6658
|
} else {
|
|
6133
|
-
|
|
6659
|
+
logger25.debug("TTL_DEBUG: No TTL set - invalid TTL value", { key, ttl });
|
|
6134
6660
|
}
|
|
6135
6661
|
}
|
|
6136
6662
|
/**
|
|
@@ -6144,7 +6670,7 @@ var TTLManager = class {
|
|
|
6144
6670
|
const now = Date.now();
|
|
6145
6671
|
const expired = now >= metadata.expiresAt;
|
|
6146
6672
|
if (expired) {
|
|
6147
|
-
|
|
6673
|
+
logger25.trace("Item expired", { key, expiresAt: metadata.expiresAt, now });
|
|
6148
6674
|
}
|
|
6149
6675
|
return expired;
|
|
6150
6676
|
}
|
|
@@ -6191,7 +6717,7 @@ var TTLManager = class {
|
|
|
6191
6717
|
}
|
|
6192
6718
|
}
|
|
6193
6719
|
if (expiredKeys.length > 0) {
|
|
6194
|
-
|
|
6720
|
+
logger25.debug("Found expired items", { count: expiredKeys.length, keys: expiredKeys });
|
|
6195
6721
|
}
|
|
6196
6722
|
return expiredKeys;
|
|
6197
6723
|
}
|
|
@@ -6219,7 +6745,7 @@ var TTLManager = class {
|
|
|
6219
6745
|
}
|
|
6220
6746
|
metadata.expiresAt += additionalTTL;
|
|
6221
6747
|
await metadataProvider.setMetadata(key, metadata);
|
|
6222
|
-
|
|
6748
|
+
logger25.trace("TTL extended for item", { key, additionalTTL, newExpiresAt: metadata.expiresAt });
|
|
6223
6749
|
return true;
|
|
6224
6750
|
}
|
|
6225
6751
|
/**
|
|
@@ -6241,7 +6767,7 @@ var TTLManager = class {
|
|
|
6241
6767
|
ttl
|
|
6242
6768
|
};
|
|
6243
6769
|
await metadataProvider.setMetadata(key, ttlMetadata);
|
|
6244
|
-
|
|
6770
|
+
logger25.trace("TTL refreshed for item", { key, ttl, expiresAt: ttlMetadata.expiresAt });
|
|
6245
6771
|
return true;
|
|
6246
6772
|
}
|
|
6247
6773
|
/**
|
|
@@ -6253,9 +6779,9 @@ var TTLManager = class {
|
|
|
6253
6779
|
}
|
|
6254
6780
|
if (this.config.cleanupInterval) {
|
|
6255
6781
|
this.cleanupTimer = setInterval(() => {
|
|
6256
|
-
|
|
6782
|
+
logger25.trace("Auto cleanup timer triggered");
|
|
6257
6783
|
}, this.config.cleanupInterval);
|
|
6258
|
-
|
|
6784
|
+
logger25.debug("Auto cleanup started", { interval: this.config.cleanupInterval });
|
|
6259
6785
|
}
|
|
6260
6786
|
}
|
|
6261
6787
|
/**
|
|
@@ -6265,7 +6791,7 @@ var TTLManager = class {
|
|
|
6265
6791
|
if (this.cleanupTimer) {
|
|
6266
6792
|
clearInterval(this.cleanupTimer);
|
|
6267
6793
|
this.cleanupTimer = null;
|
|
6268
|
-
|
|
6794
|
+
logger25.debug("Auto cleanup stopped");
|
|
6269
6795
|
}
|
|
6270
6796
|
}
|
|
6271
6797
|
/**
|
|
@@ -6273,14 +6799,14 @@ var TTLManager = class {
|
|
|
6273
6799
|
*/
|
|
6274
6800
|
clear() {
|
|
6275
6801
|
this.stopAutoCleanup();
|
|
6276
|
-
|
|
6802
|
+
logger25.debug("TTL manager cleared");
|
|
6277
6803
|
}
|
|
6278
6804
|
/**
|
|
6279
6805
|
* Cleanup resources
|
|
6280
6806
|
*/
|
|
6281
6807
|
destroy() {
|
|
6282
6808
|
this.stopAutoCleanup();
|
|
6283
|
-
|
|
6809
|
+
logger25.debug("TTL manager destroyed");
|
|
6284
6810
|
}
|
|
6285
6811
|
};
|
|
6286
6812
|
|
|
@@ -6680,9 +7206,9 @@ var CacheStatsManager = class {
|
|
|
6680
7206
|
};
|
|
6681
7207
|
|
|
6682
7208
|
// src/Cache.ts
|
|
6683
|
-
var
|
|
7209
|
+
var logger26 = logger_default.get("Cache");
|
|
6684
7210
|
var createCache = (api, coordinate, registry, options) => {
|
|
6685
|
-
|
|
7211
|
+
logger26.debug("createCache", { coordinate, registry, options });
|
|
6686
7212
|
const completeOptions = createOptions(options);
|
|
6687
7213
|
const cacheMap = createCacheMap(coordinate.kta, completeOptions);
|
|
6688
7214
|
const pkType = coordinate.kta[0];
|
|
@@ -6762,13 +7288,13 @@ var isCache2 = (cache) => {
|
|
|
6762
7288
|
};
|
|
6763
7289
|
|
|
6764
7290
|
// src/InstanceFactory.ts
|
|
6765
|
-
var
|
|
7291
|
+
var logger27 = logger_default.get("InstanceFactory");
|
|
6766
7292
|
var createInstanceFactory = (api, options) => {
|
|
6767
7293
|
const templateOptions = createOptions(options);
|
|
6768
7294
|
validateOptions(templateOptions);
|
|
6769
7295
|
return (coordinate, context) => {
|
|
6770
7296
|
const instanceOptions = createOptions(options);
|
|
6771
|
-
|
|
7297
|
+
logger27.debug("Creating cache instance", {
|
|
6772
7298
|
coordinate,
|
|
6773
7299
|
registry: context.registry,
|
|
6774
7300
|
api,
|
|
@@ -6835,9 +7361,9 @@ var createInstanceFactory = (api, options) => {
|
|
|
6835
7361
|
};
|
|
6836
7362
|
|
|
6837
7363
|
// src/Instance.ts
|
|
6838
|
-
var
|
|
7364
|
+
var logger28 = logger_default.get("Instance");
|
|
6839
7365
|
var createInstance = (registry, coordinate, api, options) => {
|
|
6840
|
-
|
|
7366
|
+
logger28.debug("createInstance", { coordinate, api, registry, options });
|
|
6841
7367
|
return createCache(api, coordinate, registry, options);
|
|
6842
7368
|
};
|
|
6843
7369
|
var isInstance = (instance) => {
|
|
@@ -6845,7 +7371,7 @@ var isInstance = (instance) => {
|
|
|
6845
7371
|
};
|
|
6846
7372
|
|
|
6847
7373
|
// src/Aggregator.ts
|
|
6848
|
-
var
|
|
7374
|
+
var logger29 = logger_default.get("ItemAggregator");
|
|
6849
7375
|
var toCacheConfig = (config) => {
|
|
6850
7376
|
let cacheConfig;
|
|
6851
7377
|
if (config.optional === void 0) {
|
|
@@ -6857,22 +7383,22 @@ var toCacheConfig = (config) => {
|
|
|
6857
7383
|
};
|
|
6858
7384
|
var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
6859
7385
|
const populate = async (item) => {
|
|
6860
|
-
|
|
7386
|
+
logger29.default("populate", { item });
|
|
6861
7387
|
for (const key in aggregates) {
|
|
6862
7388
|
await populateAggregate(key, item);
|
|
6863
7389
|
}
|
|
6864
7390
|
for (const key in events) {
|
|
6865
7391
|
await populateEvent(key, item);
|
|
6866
7392
|
}
|
|
6867
|
-
|
|
7393
|
+
logger29.default("populate done", { item });
|
|
6868
7394
|
return item;
|
|
6869
7395
|
};
|
|
6870
7396
|
const populateAggregate = async (key, item) => {
|
|
6871
|
-
|
|
7397
|
+
logger29.default("populate aggregate key", { key });
|
|
6872
7398
|
const cacheConfig = toCacheConfig(aggregates[key]);
|
|
6873
7399
|
if (item.refs === void 0) {
|
|
6874
7400
|
if (cacheConfig.optional === false) {
|
|
6875
|
-
|
|
7401
|
+
logger29.error("Item does not have refs an is not optional ", { item });
|
|
6876
7402
|
throw new Error("Item does not have refs an is not optional " + JSON.stringify(item));
|
|
6877
7403
|
} else {
|
|
6878
7404
|
if (item.events && Object.prototype.hasOwnProperty.call(item.events, key)) {
|
|
@@ -6881,7 +7407,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6881
7407
|
}
|
|
6882
7408
|
} else if (item.refs[key] === void 0) {
|
|
6883
7409
|
if (cacheConfig.optional === false) {
|
|
6884
|
-
|
|
7410
|
+
logger29.error("Item does not have mandatory ref with key, not optional ", { key, item });
|
|
6885
7411
|
throw new Error("Item does not have mandatory ref with key, not optional " + key + " " + JSON.stringify(item));
|
|
6886
7412
|
} else {
|
|
6887
7413
|
if (item.events && Object.prototype.hasOwnProperty.call(item.events, key)) {
|
|
@@ -6890,7 +7416,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6890
7416
|
}
|
|
6891
7417
|
} else {
|
|
6892
7418
|
const ref = item.refs[key];
|
|
6893
|
-
|
|
7419
|
+
logger29.default("AGG Retrieving Item in Populate", { key: ref });
|
|
6894
7420
|
const newItem = await cacheConfig.cache.operations.retrieve(ref);
|
|
6895
7421
|
if (newItem) {
|
|
6896
7422
|
if (item.aggs === void 0) {
|
|
@@ -6907,25 +7433,25 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6907
7433
|
}
|
|
6908
7434
|
};
|
|
6909
7435
|
const populateEvent = async (key, item) => {
|
|
6910
|
-
|
|
7436
|
+
logger29.default("populate event key", { key });
|
|
6911
7437
|
const cacheConfig = toCacheConfig(events[key]);
|
|
6912
7438
|
if (item.events === void 0) {
|
|
6913
7439
|
throw new Error("Item does not have events " + JSON.stringify(item));
|
|
6914
7440
|
} else if (item.events[key] === void 0) {
|
|
6915
7441
|
if (cacheConfig.optional === false) {
|
|
6916
|
-
|
|
7442
|
+
logger29.error("Item does not have mandatory event with key", { key, item });
|
|
6917
7443
|
throw new Error("Item does not have mandatory event with key " + key + " " + JSON.stringify(item));
|
|
6918
7444
|
}
|
|
6919
7445
|
} else {
|
|
6920
7446
|
const event = item.events[key];
|
|
6921
7447
|
if (event.by === void 0) {
|
|
6922
|
-
|
|
7448
|
+
logger29.error(
|
|
6923
7449
|
"populateEvent with an Event that does not have by",
|
|
6924
7450
|
{ event, ik: item.key, eventKey: key }
|
|
6925
7451
|
);
|
|
6926
7452
|
throw new Error("populateEvent with an Event that does not have by: " + JSON.stringify({ key }));
|
|
6927
7453
|
}
|
|
6928
|
-
|
|
7454
|
+
logger29.default("EVENT Retrieving Item in Populate", { key: event.by });
|
|
6929
7455
|
const newItem = await cacheConfig.cache.operations.retrieve(event.by);
|
|
6930
7456
|
if (newItem) {
|
|
6931
7457
|
event.agg = newItem;
|
|
@@ -6933,13 +7459,13 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6933
7459
|
}
|
|
6934
7460
|
};
|
|
6935
7461
|
const all2 = async (query = {}, locations = []) => {
|
|
6936
|
-
|
|
7462
|
+
logger29.default("all", { query, locations });
|
|
6937
7463
|
const items = await cache.operations.all(query, locations);
|
|
6938
7464
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6939
7465
|
return populatedItems;
|
|
6940
7466
|
};
|
|
6941
7467
|
const one2 = async (query = {}, locations = []) => {
|
|
6942
|
-
|
|
7468
|
+
logger29.default("one", { query, locations });
|
|
6943
7469
|
const item = await cache.operations.one(query, locations);
|
|
6944
7470
|
let populatedItem = null;
|
|
6945
7471
|
if (item) {
|
|
@@ -6948,30 +7474,30 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6948
7474
|
return populatedItem;
|
|
6949
7475
|
};
|
|
6950
7476
|
const action2 = async (key, action3, body = {}) => {
|
|
6951
|
-
|
|
7477
|
+
logger29.default("action", { key, action: action3, body });
|
|
6952
7478
|
const [item, affectedItems] = await cache.operations.action(key, action3, body);
|
|
6953
7479
|
const populatedItem = await populate(item);
|
|
6954
7480
|
return [populatedItem, affectedItems];
|
|
6955
7481
|
};
|
|
6956
7482
|
const allAction2 = async (action3, body = {}, locations = []) => {
|
|
6957
|
-
|
|
7483
|
+
logger29.default("action", { action: action3, body, locations });
|
|
6958
7484
|
const [items, affectedItems] = await cache.operations.allAction(action3, body, locations);
|
|
6959
7485
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6960
7486
|
return [populatedItems, affectedItems];
|
|
6961
7487
|
};
|
|
6962
7488
|
const allFacet2 = async (facet3, params = {}, locations = []) => {
|
|
6963
|
-
|
|
7489
|
+
logger29.default("allFacet", { facet: facet3, params, locations });
|
|
6964
7490
|
const response = await cache.operations.allFacet(facet3, params, locations);
|
|
6965
7491
|
return response;
|
|
6966
7492
|
};
|
|
6967
7493
|
const create2 = async (v, locations = []) => {
|
|
6968
|
-
|
|
7494
|
+
logger29.default("create", { v, locations });
|
|
6969
7495
|
const item = locations.length === 0 ? await cache.operations.create(v) : await cache.operations.create(v, { locations });
|
|
6970
7496
|
const populatedItem = await populate(item);
|
|
6971
7497
|
return populatedItem;
|
|
6972
7498
|
};
|
|
6973
7499
|
const get2 = async (key) => {
|
|
6974
|
-
|
|
7500
|
+
logger29.default("get", { key });
|
|
6975
7501
|
const item = await cache.operations.get(key);
|
|
6976
7502
|
let populatedItem = null;
|
|
6977
7503
|
if (item) {
|
|
@@ -6980,7 +7506,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6980
7506
|
return populatedItem;
|
|
6981
7507
|
};
|
|
6982
7508
|
const retrieve2 = async (key) => {
|
|
6983
|
-
|
|
7509
|
+
logger29.default("retrieve", { key });
|
|
6984
7510
|
const item = await cache.operations.retrieve(key);
|
|
6985
7511
|
let populatedItem = null;
|
|
6986
7512
|
if (item) {
|
|
@@ -6989,28 +7515,28 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6989
7515
|
return populatedItem;
|
|
6990
7516
|
};
|
|
6991
7517
|
const remove2 = async (key) => {
|
|
6992
|
-
|
|
7518
|
+
logger29.default("remove", { key });
|
|
6993
7519
|
await cache.operations.remove(key);
|
|
6994
7520
|
};
|
|
6995
7521
|
const update2 = async (key, v) => {
|
|
6996
|
-
|
|
7522
|
+
logger29.default("update", { key, v });
|
|
6997
7523
|
const item = await cache.operations.update(key, v);
|
|
6998
7524
|
const populatedItem = await populate(item);
|
|
6999
7525
|
return populatedItem;
|
|
7000
7526
|
};
|
|
7001
7527
|
const facet2 = async (key, facet3) => {
|
|
7002
|
-
|
|
7528
|
+
logger29.default("facet", { key, facet: facet3 });
|
|
7003
7529
|
const response = await cache.operations.facet(key, facet3);
|
|
7004
7530
|
return response;
|
|
7005
7531
|
};
|
|
7006
7532
|
const find2 = async (finder, finderParams = {}, locations = []) => {
|
|
7007
|
-
|
|
7533
|
+
logger29.default("find", { finder, finderParams, locations });
|
|
7008
7534
|
const items = await cache.operations.find(finder, finderParams, locations);
|
|
7009
7535
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
7010
7536
|
return populatedItems;
|
|
7011
7537
|
};
|
|
7012
7538
|
const findOne2 = async (finder, finderParams = {}, locations = []) => {
|
|
7013
|
-
|
|
7539
|
+
logger29.default("find", { finder, finderParams, locations });
|
|
7014
7540
|
const item = await cache.operations.findOne(finder, finderParams, locations);
|
|
7015
7541
|
if (!item) {
|
|
7016
7542
|
return null;
|
|
@@ -7019,7 +7545,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
7019
7545
|
return populatedItem;
|
|
7020
7546
|
};
|
|
7021
7547
|
const set2 = async (key, v) => {
|
|
7022
|
-
|
|
7548
|
+
logger29.default("set", { key, v });
|
|
7023
7549
|
const item = await cache.operations.set(key, v);
|
|
7024
7550
|
const populatedItem = await populate(item);
|
|
7025
7551
|
return populatedItem;
|
|
@@ -7071,13 +7597,13 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
7071
7597
|
import {
|
|
7072
7598
|
createRegistry as createBaseRegistry
|
|
7073
7599
|
} from "@fjell/registry";
|
|
7074
|
-
var
|
|
7600
|
+
var logger30 = logger_default.get("Registry");
|
|
7075
7601
|
var createRegistryFactory = () => {
|
|
7076
7602
|
return (type, registryHub) => {
|
|
7077
7603
|
if (type !== "cache") {
|
|
7078
7604
|
throw new Error(`Cache registry factory can only create 'cache' type registries, got: ${type}`);
|
|
7079
7605
|
}
|
|
7080
|
-
|
|
7606
|
+
logger30.debug("Creating cache registry", { type, registryHub });
|
|
7081
7607
|
const baseRegistry = createBaseRegistry(type, registryHub);
|
|
7082
7608
|
return baseRegistry;
|
|
7083
7609
|
};
|