@fjell/cache 4.7.45 → 4.7.47
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/dist/index.js +34 -8
- package/dist/ops/all.d.ts +1 -0
- package/dist/ops/all.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -791,6 +791,18 @@ var CacheEventFactory = class {
|
|
|
791
791
|
|
|
792
792
|
// src/ops/all.ts
|
|
793
793
|
var logger2 = logger_default.get("all");
|
|
794
|
+
var inFlightRequests = /* @__PURE__ */ new Map();
|
|
795
|
+
var CLEANUP_INTERVAL = 3e4;
|
|
796
|
+
var REQUEST_TIMEOUT = 25e3;
|
|
797
|
+
setInterval(() => {
|
|
798
|
+
const now = Date.now();
|
|
799
|
+
inFlightRequests.forEach((request, key) => {
|
|
800
|
+
if (now - request.timestamp > REQUEST_TIMEOUT) {
|
|
801
|
+
logger2.debug("Cleaning up stale in-flight all() request", { key });
|
|
802
|
+
inFlightRequests.delete(key);
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
}, CLEANUP_INTERVAL);
|
|
794
806
|
var all = async (query = {}, locations = [], context) => {
|
|
795
807
|
const { api, cacheMap, pkType, ttlManager, coordinate } = context;
|
|
796
808
|
logger2.default("all", { query, locations });
|
|
@@ -913,9 +925,22 @@ async function executeAllLogic(query, locations, context) {
|
|
|
913
925
|
query: JSON.stringify(query),
|
|
914
926
|
locations: JSON.stringify(locations)
|
|
915
927
|
});
|
|
928
|
+
const timestamp = Date.now();
|
|
929
|
+
const existingRequest = inFlightRequests.get(queryHash);
|
|
930
|
+
if (existingRequest && timestamp - existingRequest.timestamp < REQUEST_TIMEOUT) {
|
|
931
|
+
logger2.debug("QUERY_CACHE: Using existing in-flight all() request", {
|
|
932
|
+
queryHash,
|
|
933
|
+
age: timestamp - existingRequest.timestamp
|
|
934
|
+
});
|
|
935
|
+
return await existingRequest.promise;
|
|
936
|
+
}
|
|
916
937
|
let ret = [];
|
|
917
938
|
try {
|
|
918
|
-
|
|
939
|
+
const apiRequest = api.all(query, locations);
|
|
940
|
+
inFlightRequests.set(queryHash, { promise: apiRequest, timestamp });
|
|
941
|
+
const cleanup = () => inFlightRequests.delete(queryHash);
|
|
942
|
+
apiRequest.then(cleanup, cleanup);
|
|
943
|
+
ret = await apiRequest;
|
|
919
944
|
logger2.debug("QUERY_CACHE: API response received", {
|
|
920
945
|
queryHash,
|
|
921
946
|
itemCount: ret.length,
|
|
@@ -954,6 +979,7 @@ async function executeAllLogic(query, locations, context) {
|
|
|
954
979
|
context.eventEmitter.emit(event);
|
|
955
980
|
logger2.debug("QUERY_CACHE: Emitted query event", { queryHash });
|
|
956
981
|
} catch (e) {
|
|
982
|
+
inFlightRequests.delete(queryHash);
|
|
957
983
|
if (e instanceof NotFoundError) {
|
|
958
984
|
logger2.debug("QUERY_CACHE: API returned NotFoundError, caching empty result", { queryHash });
|
|
959
985
|
await cacheMap.setQueryResult(queryHash, []);
|
|
@@ -1361,19 +1387,19 @@ import {
|
|
|
1361
1387
|
isValidItemKey
|
|
1362
1388
|
} from "@fjell/core";
|
|
1363
1389
|
var logger5 = logger_default.get("get");
|
|
1364
|
-
var
|
|
1390
|
+
var inFlightRequests2 = /* @__PURE__ */ new Map();
|
|
1365
1391
|
var CLEANUP_TIMEOUT = 5 * 60 * 1e3;
|
|
1366
1392
|
var cleanupStaleRequests = () => {
|
|
1367
1393
|
const now = Date.now();
|
|
1368
1394
|
const keysToDelete = [];
|
|
1369
|
-
|
|
1395
|
+
inFlightRequests2.forEach((request, key) => {
|
|
1370
1396
|
if (now - request.timestamp > CLEANUP_TIMEOUT) {
|
|
1371
1397
|
keysToDelete.push(key);
|
|
1372
1398
|
}
|
|
1373
1399
|
});
|
|
1374
1400
|
keysToDelete.forEach((key) => {
|
|
1375
1401
|
logger5.debug("Cleaning up stale in-flight request", { key });
|
|
1376
|
-
|
|
1402
|
+
inFlightRequests2.delete(key);
|
|
1377
1403
|
});
|
|
1378
1404
|
};
|
|
1379
1405
|
var cleanupInterval = setInterval(cleanupStaleRequests, 60 * 1e3);
|
|
@@ -1503,7 +1529,7 @@ async function executeGetLogic(key, context) {
|
|
|
1503
1529
|
let ret;
|
|
1504
1530
|
const requestKeyStr = keyToString(key);
|
|
1505
1531
|
try {
|
|
1506
|
-
const requestEntry =
|
|
1532
|
+
const requestEntry = inFlightRequests2.get(requestKeyStr);
|
|
1507
1533
|
let apiRequest;
|
|
1508
1534
|
const apiStartTime = Date.now();
|
|
1509
1535
|
if (!requestEntry) {
|
|
@@ -1511,8 +1537,8 @@ async function executeGetLogic(key, context) {
|
|
|
1511
1537
|
apiRequest = api.get(key);
|
|
1512
1538
|
if (apiRequest && typeof apiRequest.then === "function") {
|
|
1513
1539
|
const timestamp = Date.now();
|
|
1514
|
-
|
|
1515
|
-
const cleanup = () =>
|
|
1540
|
+
inFlightRequests2.set(requestKeyStr, { promise: apiRequest, timestamp });
|
|
1541
|
+
const cleanup = () => inFlightRequests2.delete(requestKeyStr);
|
|
1516
1542
|
if (typeof apiRequest.finally === "function") {
|
|
1517
1543
|
apiRequest.finally(cleanup);
|
|
1518
1544
|
} else {
|
|
@@ -1596,7 +1622,7 @@ async function executeGetLogic(key, context) {
|
|
|
1596
1622
|
});
|
|
1597
1623
|
}
|
|
1598
1624
|
} catch (e) {
|
|
1599
|
-
|
|
1625
|
+
inFlightRequests2.delete(requestKeyStr);
|
|
1600
1626
|
const duration = Date.now() - startTime;
|
|
1601
1627
|
logger5.error("CACHE_OP: Error in get() operation", {
|
|
1602
1628
|
key: keyStr,
|
package/dist/ops/all.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Item, ItemQuery, LocKeyArray } from "@fjell/core";
|
|
2
2
|
import { CacheContext } from "../CacheContext";
|
|
3
|
+
export declare const clearInFlightRequests: () => void;
|
|
3
4
|
export declare const all: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(query: ItemQuery | undefined, locations: (LocKeyArray<L1, L2, L3, L4, L5> | []) | undefined, context: CacheContext<V, S, L1, L2, L3, L4, L5>) => Promise<[CacheContext<V, S, L1, L2, L3, L4, L5>, V[]]>;
|
|
4
5
|
//# sourceMappingURL=all.d.ts.map
|
package/dist/ops/all.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/ops/all.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,SAAS,EACT,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/ops/all.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,SAAS,EACT,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAyB/C,eAAO,MAAM,qBAAqB,YAEjC,CAAC;AAEF,eAAO,MAAM,GAAG,GACd,CAAC,SAAS,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EACrC,CAAC,SAAS,MAAM,EAChB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EAEzB,OAAO,SAAS,YAAK,EACrB,YAAW,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,aAAK,EACpD,SAAS,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,KAC9C,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAcvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fjell/cache",
|
|
3
3
|
"description": "Cache for Fjell",
|
|
4
|
-
"version": "4.7.
|
|
4
|
+
"version": "4.7.47",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cache",
|
|
7
7
|
"fjell"
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"docs:test": "cd docs && npm run test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@fjell/client-api": "^4.4.
|
|
41
|
-
"@fjell/core": "^4.4.
|
|
42
|
-
"@fjell/http-api": "^4.4.
|
|
40
|
+
"@fjell/client-api": "^4.4.56",
|
|
41
|
+
"@fjell/core": "^4.4.62",
|
|
42
|
+
"@fjell/http-api": "^4.4.52",
|
|
43
43
|
"@fjell/logging": "^4.4.58",
|
|
44
|
-
"@fjell/registry": "^4.4.
|
|
44
|
+
"@fjell/registry": "^4.4.68",
|
|
45
45
|
"fast-safe-stringify": "^2.1.1",
|
|
46
46
|
"flatted": "^3.3.3",
|
|
47
47
|
"yocto-queue": "^1.2.1"
|