tricache 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dashboards/prometheus-scrape.yml +18 -0
- package/dist/{cache-service-5MZXFIGK.js → cache-service-26GCO3UU.js} +3 -3
- package/dist/{cache-service-CyLdpo77.d.ts → cache-service-pJ-nFcVj.d.ts} +44 -12
- package/dist/{chunk-XZL45ABR.js → chunk-2AJKEQMZ.js} +54 -1
- package/dist/{chunk-6PQ5MOWR.js → chunk-7SZSQS55.js} +571 -115
- package/dist/chunk-BQRURGGD.js +60 -0
- package/dist/chunk-IITRFWHY.js +196 -0
- package/dist/{chunk-LJ5QJB5O.js → chunk-UBWLPKTI.js} +127 -11
- package/dist/cli.cjs +767 -133
- package/dist/cli.js +24 -6
- package/dist/dashboard/index.d.ts +2 -2
- package/dist/drizzle/index.cjs +734 -132
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +163 -46
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +42 -14
- package/dist/hono/index.cjs +8093 -0
- package/dist/hono/index.d.ts +91 -0
- package/dist/hono/index.js +185 -0
- package/dist/{hono-DQRS1Xd7.d.ts → hono-DuNvciyq.d.ts} +6 -5
- package/dist/http/index.cjs +833 -170
- package/dist/http/index.d.ts +6 -30
- package/dist/http/index.js +9 -59
- package/dist/index.cjs +755 -130
- package/dist/index.d.ts +35 -6
- package/dist/index.js +16 -6
- package/dist/nestjs/index.cjs +725 -130
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +4 -4
- package/dist/next/index.cjs +725 -130
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +3 -3
- package/dist/prisma/index.d.ts +2 -2
- package/dist/serialize-worker.cjs +127 -9
- package/dist/serialize-worker.js +8 -4
- package/dist/{types-B6krw64X.d.ts → types-5HXqBfAf.d.ts} +74 -7
- package/dist/utils-CEsU_Z0s.d.ts +27 -0
- package/package.json +22 -9
- package/src/cache-service.ts +540 -68
- package/src/cli.ts +21 -4
- package/src/compression.ts +193 -15
- package/src/cross-region.ts +1 -1
- package/src/edge/cache.ts +38 -11
- package/src/edge/hono.ts +123 -42
- package/src/env.d.ts +13 -0
- package/src/hono/index.ts +316 -0
- package/src/http/index.ts +5 -0
- package/src/index.ts +9 -1
- package/src/ipc-telemetry.ts +29 -1
- package/src/serialize-worker.ts +6 -2
- package/src/types.ts +68 -5
- package/src/utils/tag-matcher.ts +90 -0
- package/dist/chunk-ZTSWCFYO.js +0 -135
- /package/dist/{chunk-QNU7B43J.js → chunk-VXFTFZ5N.js} +0 -0
package/dist/drizzle/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CacheService } from '../cache-service-
|
|
2
|
-
import { W as WrapOptions } from '../types-
|
|
1
|
+
import { C as CacheService } from '../cache-service-pJ-nFcVj.js';
|
|
2
|
+
import { W as WrapOptions } from '../types-5HXqBfAf.js';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/drizzle/index.js
CHANGED
|
@@ -9,7 +9,7 @@ async function withCache(query, options = {}) {
|
|
|
9
9
|
const { cache, key, ttl = 300, swr, priority, tags, dependsOn, refreshAhead, xfetchBeta, notFoundTtl } = options;
|
|
10
10
|
let activeCache = cache;
|
|
11
11
|
if (!activeCache) {
|
|
12
|
-
const { CacheService } = await import("../cache-service-
|
|
12
|
+
const { CacheService } = await import("../cache-service-26GCO3UU.js");
|
|
13
13
|
activeCache = CacheService.create();
|
|
14
14
|
}
|
|
15
15
|
let cacheKey = key;
|
package/dist/edge/index.cjs
CHANGED
|
@@ -406,6 +406,37 @@ var Murmur3BloomFilter = class {
|
|
|
406
406
|
}
|
|
407
407
|
};
|
|
408
408
|
|
|
409
|
+
// src/utils/tag-matcher.ts
|
|
410
|
+
var globRegexCache = /* @__PURE__ */ new Map();
|
|
411
|
+
function isWildcardTag(tag) {
|
|
412
|
+
return tag.includes("*") || tag.includes("?");
|
|
413
|
+
}
|
|
414
|
+
function matchesTagPattern(pattern, tag) {
|
|
415
|
+
if (pattern === "*" || pattern === tag) return true;
|
|
416
|
+
if (!pattern.includes("*") && !pattern.includes("?")) return pattern === tag;
|
|
417
|
+
if (pattern.endsWith("*") && !pattern.slice(0, -1).includes("*") && !pattern.includes("?")) {
|
|
418
|
+
const prefix = pattern.slice(0, -1);
|
|
419
|
+
return tag.startsWith(prefix);
|
|
420
|
+
}
|
|
421
|
+
if (pattern.startsWith("*") && !pattern.slice(1).includes("*") && !pattern.includes("?")) {
|
|
422
|
+
const suffix = pattern.slice(1);
|
|
423
|
+
return tag.endsWith(suffix);
|
|
424
|
+
}
|
|
425
|
+
let re = globRegexCache.get(pattern);
|
|
426
|
+
if (!re) {
|
|
427
|
+
if (globRegexCache.size >= 1e3) globRegexCache.clear();
|
|
428
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
429
|
+
re = new RegExp(`^${escaped}$`);
|
|
430
|
+
globRegexCache.set(pattern, re);
|
|
431
|
+
}
|
|
432
|
+
return re.test(tag);
|
|
433
|
+
}
|
|
434
|
+
function isChildTag(parentTag, candidateTag, delimiter = ":") {
|
|
435
|
+
if (candidateTag === parentTag) return true;
|
|
436
|
+
const prefix = parentTag.endsWith(delimiter) ? parentTag : `${parentTag}${delimiter}`;
|
|
437
|
+
return candidateTag.startsWith(prefix);
|
|
438
|
+
}
|
|
439
|
+
|
|
409
440
|
// src/edge/cache.ts
|
|
410
441
|
var EdgeCacheService = class {
|
|
411
442
|
maxKeys;
|
|
@@ -716,11 +747,12 @@ var EdgeCacheService = class {
|
|
|
716
747
|
const nsKey = this.nk(key);
|
|
717
748
|
const resolvedTtl = ttlSeconds ?? this.defaultTtl;
|
|
718
749
|
const now = Date.now();
|
|
719
|
-
const
|
|
750
|
+
const optObj = Array.isArray(options) ? { tags: options } : options;
|
|
751
|
+
const swrSeconds = optObj?.swr ?? 0;
|
|
720
752
|
try {
|
|
721
753
|
let activeTagVersions;
|
|
722
|
-
if (
|
|
723
|
-
activeTagVersions = await this._batchGetTagVersions(
|
|
754
|
+
if (optObj?.tags?.length) {
|
|
755
|
+
activeTagVersions = await this._batchGetTagVersions(optObj.tags);
|
|
724
756
|
}
|
|
725
757
|
const serialized = JSON.stringify(value);
|
|
726
758
|
const bytes = this._estimateBytes(nsKey, serialized);
|
|
@@ -732,13 +764,13 @@ var EdgeCacheService = class {
|
|
|
732
764
|
bytes,
|
|
733
765
|
expiresAt: now + resolvedTtl * 1e3,
|
|
734
766
|
staleUntil: now + (resolvedTtl + swrSeconds) * 1e3,
|
|
735
|
-
tags:
|
|
767
|
+
tags: optObj?.tags,
|
|
736
768
|
tagVersions: activeTagVersions
|
|
737
769
|
};
|
|
738
770
|
this.l1.set(nsKey, entry);
|
|
739
771
|
this.currentBytes += bytes;
|
|
740
|
-
if (
|
|
741
|
-
for (const tag of
|
|
772
|
+
if (optObj?.tags) {
|
|
773
|
+
for (const tag of optObj.tags) {
|
|
742
774
|
let s = this.tagIndex.get(tag);
|
|
743
775
|
if (!s) {
|
|
744
776
|
s = /* @__PURE__ */ new Set();
|
|
@@ -786,10 +818,33 @@ var EdgeCacheService = class {
|
|
|
786
818
|
/**
|
|
787
819
|
* Invalidates all cached entries associated with a tag.
|
|
788
820
|
*/
|
|
789
|
-
async invalidateTag(tag) {
|
|
821
|
+
async invalidateTag(tag, opts) {
|
|
790
822
|
const span = this._startSpan("tricache.invalidate_tag");
|
|
791
823
|
span.setAttribute("cache.tag", tag);
|
|
824
|
+
if (opts?.cascade) span.setAttribute("cache.cascade", true);
|
|
792
825
|
try {
|
|
826
|
+
const isPattern = isWildcardTag(tag);
|
|
827
|
+
const shouldCascade = Boolean(opts?.cascade);
|
|
828
|
+
if (isPattern || shouldCascade) {
|
|
829
|
+
const matched = /* @__PURE__ */ new Set();
|
|
830
|
+
const tagMatches = (t) => {
|
|
831
|
+
if (t === tag) return true;
|
|
832
|
+
if (isPattern && matchesTagPattern(tag, t)) return true;
|
|
833
|
+
if (shouldCascade && isChildTag(tag, t, ":")) return true;
|
|
834
|
+
return false;
|
|
835
|
+
};
|
|
836
|
+
for (const t of this.tagIndex.keys()) {
|
|
837
|
+
if (tagMatches(t)) matched.add(t);
|
|
838
|
+
}
|
|
839
|
+
for (const t of this.tagVersionCache.keys()) {
|
|
840
|
+
if (tagMatches(t)) matched.add(t);
|
|
841
|
+
}
|
|
842
|
+
if (shouldCascade && !isPattern) matched.add(tag);
|
|
843
|
+
for (const t of matched) {
|
|
844
|
+
await this.invalidateTag(t);
|
|
845
|
+
}
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
793
848
|
let newVer = 1;
|
|
794
849
|
if (this.remoteStorage) {
|
|
795
850
|
try {
|
|
@@ -873,9 +928,10 @@ var EdgeCacheService = class {
|
|
|
873
928
|
span.setAttribute("cache.misses", missKeys.length);
|
|
874
929
|
if (missKeys.length > 0 && fetchFn) {
|
|
875
930
|
const fetchedMap = await fetchFn(missKeys);
|
|
931
|
+
const isMap = fetchedMap instanceof Map;
|
|
876
932
|
for (let j = 0; j < missKeys.length; j++) {
|
|
877
933
|
const k = missKeys[j];
|
|
878
|
-
const fetchedVal = fetchedMap[k];
|
|
934
|
+
const fetchedVal = isMap ? fetchedMap.get(k) : fetchedMap[k];
|
|
879
935
|
if (fetchedVal !== void 0) {
|
|
880
936
|
results[missIndices[j]] = fetchedVal;
|
|
881
937
|
await this.set(k, fetchedVal, ttlSeconds);
|
|
@@ -1403,6 +1459,15 @@ function buildEdgeDeterministicKey(c, options) {
|
|
|
1403
1459
|
}
|
|
1404
1460
|
return key;
|
|
1405
1461
|
}
|
|
1462
|
+
var NonCacheableEdgeResponseError = class extends Error {
|
|
1463
|
+
constructor(response) {
|
|
1464
|
+
super(`Non-cacheable status: ${response.status}`);
|
|
1465
|
+
this.response = response;
|
|
1466
|
+
this.name = "NonCacheableEdgeResponseError";
|
|
1467
|
+
}
|
|
1468
|
+
response;
|
|
1469
|
+
isNonCacheable = true;
|
|
1470
|
+
};
|
|
1406
1471
|
function honoEdgeCache(options = {}) {
|
|
1407
1472
|
const {
|
|
1408
1473
|
cache,
|
|
@@ -1435,49 +1500,101 @@ function honoEdgeCache(options = {}) {
|
|
|
1435
1500
|
const key = buildEdgeDeterministicKey(c, { keyGenerator, headerWhitelist });
|
|
1436
1501
|
const ifNoneMatch = c.req.header?.("if-none-match") || c.req.header?.("If-None-Match");
|
|
1437
1502
|
const resolvedTags = typeof tags === "function" ? tags(c) : tags;
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1503
|
+
let ranNext = false;
|
|
1504
|
+
try {
|
|
1505
|
+
const cached = await cache.get(
|
|
1506
|
+
key,
|
|
1507
|
+
async () => {
|
|
1508
|
+
ranNext = true;
|
|
1509
|
+
await next();
|
|
1510
|
+
const res = c.res;
|
|
1511
|
+
if (!res) {
|
|
1512
|
+
return null;
|
|
1513
|
+
}
|
|
1514
|
+
const contentType = res.headers?.get?.("content-type") || "text/plain; charset=utf-8";
|
|
1515
|
+
if (contentType.toLowerCase().includes("text/event-stream")) {
|
|
1516
|
+
throw new NonCacheableEdgeResponseError({
|
|
1517
|
+
body: "",
|
|
1518
|
+
contentType,
|
|
1519
|
+
status: 0
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
const cc2 = res.headers?.get?.("cache-control");
|
|
1523
|
+
if (cc2) {
|
|
1524
|
+
const lowerCc = cc2.toLowerCase();
|
|
1525
|
+
if (lowerCc.includes("no-store") || lowerCc.includes("no-cache") || lowerCc.includes("private")) {
|
|
1526
|
+
throw new NonCacheableEdgeResponseError({
|
|
1527
|
+
body: "",
|
|
1528
|
+
contentType,
|
|
1529
|
+
status: 0
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
const statusCode = res.status ?? 200;
|
|
1534
|
+
if (statusCode < 200 || statusCode >= 300 || statusCode === 206) {
|
|
1535
|
+
throw new NonCacheableEdgeResponseError({
|
|
1536
|
+
body: "",
|
|
1537
|
+
contentType,
|
|
1538
|
+
status: statusCode
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
const clone = res.clone();
|
|
1542
|
+
const text = await clone.text();
|
|
1543
|
+
const bodyEtag = etag ? await computeEdgeETag(text) : void 0;
|
|
1544
|
+
const capturedHeaders = {};
|
|
1545
|
+
if (res.headers && typeof res.headers.forEach === "function") {
|
|
1546
|
+
res.headers.forEach((value, name) => {
|
|
1547
|
+
const lower = name.toLowerCase();
|
|
1548
|
+
if (lower !== "content-length" && lower !== "transfer-encoding" && lower !== "connection" && lower !== "etag" && lower !== "content-type") {
|
|
1549
|
+
capturedHeaders[name] = value;
|
|
1550
|
+
}
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
const snapshot = {
|
|
1554
|
+
body: text,
|
|
1555
|
+
contentType,
|
|
1556
|
+
headers: capturedHeaders,
|
|
1557
|
+
etag: bodyEtag,
|
|
1558
|
+
status: statusCode
|
|
1559
|
+
};
|
|
1560
|
+
return snapshot;
|
|
1561
|
+
},
|
|
1562
|
+
ttl,
|
|
1563
|
+
{
|
|
1564
|
+
swr,
|
|
1565
|
+
tags: resolvedTags,
|
|
1566
|
+
ctx: c.executionCtx
|
|
1445
1567
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
const bodyEtag = etag ? await computeEdgeETag(text) : void 0;
|
|
1450
|
-
const contentType = res.headers.get("content-type") || "text/plain; charset=utf-8";
|
|
1451
|
-
return {
|
|
1452
|
-
body: text,
|
|
1453
|
-
contentType,
|
|
1454
|
-
etag: bodyEtag,
|
|
1455
|
-
status: statusCode
|
|
1456
|
-
};
|
|
1457
|
-
},
|
|
1458
|
-
ttl,
|
|
1459
|
-
{
|
|
1460
|
-
swr,
|
|
1461
|
-
tags: resolvedTags,
|
|
1462
|
-
ctx: c.executionCtx
|
|
1568
|
+
);
|
|
1569
|
+
if (!cached) {
|
|
1570
|
+
return;
|
|
1463
1571
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
return c.body
|
|
1572
|
+
if (cached.etag && ifNoneMatch === cached.etag) {
|
|
1573
|
+
const notModifiedHeaders = { ETag: cached.etag };
|
|
1574
|
+
if (cached.headers?.["cache-control"]) notModifiedHeaders["Cache-Control"] = cached.headers["cache-control"];
|
|
1575
|
+
if (cached.headers?.["vary"]) notModifiedHeaders["Vary"] = cached.headers["vary"];
|
|
1576
|
+
return applyEdgeResponse(c, null, 304, notModifiedHeaders);
|
|
1577
|
+
}
|
|
1578
|
+
const headers = { ...cached.headers };
|
|
1579
|
+
if (cached.etag) headers["ETag"] = cached.etag;
|
|
1580
|
+
if (cached.contentType) headers["Content-Type"] = cached.contentType;
|
|
1581
|
+
return applyEdgeResponse(c, cached.body, cached.status ?? 200, headers);
|
|
1582
|
+
} catch (err) {
|
|
1583
|
+
if (err instanceof NonCacheableEdgeResponseError) {
|
|
1584
|
+
if (!ranNext) {
|
|
1585
|
+
return await next();
|
|
1586
|
+
}
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
throw err;
|
|
1474
1590
|
}
|
|
1475
|
-
const headers = {};
|
|
1476
|
-
if (cached.etag) headers["ETag"] = cached.etag;
|
|
1477
|
-
if (cached.contentType) headers["Content-Type"] = cached.contentType;
|
|
1478
|
-
return c.body(cached.body, cached.status ?? 200, headers);
|
|
1479
1591
|
};
|
|
1480
1592
|
}
|
|
1593
|
+
function applyEdgeResponse(c, body, status, headers) {
|
|
1594
|
+
const response = c.body(body, status, headers);
|
|
1595
|
+
c.res = response;
|
|
1596
|
+
return response;
|
|
1597
|
+
}
|
|
1481
1598
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1482
1599
|
0 && (module.exports = {
|
|
1483
1600
|
CloudflareDOStorageAdapter,
|
package/dist/edge/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { I as IEdgeRemoteStorage, U as UpstashRedisOptions, a as CloudflareKVNamespace, d as CloudflareDOStorage } from '../hono-
|
|
2
|
-
export { C as CachedEdgeHttpResponse, e as CloudflareR2Bucket, f as CloudflareR2Object, E as EdgeCacheOptions, g as EdgeCacheService, i as EdgeExportSnapshotOptions, j as EdgeGetOptions, k as EdgeHydrateOptions, l as EdgeSnapshotPayload, m as EdgeSnapshotSource, H as HonoEdgeCacheOptions, n as IEdgeBloomFilter, b as buildEdgeDeterministicKey, c as computeEdgeETag, h as honoEdgeCache } from '../hono-
|
|
1
|
+
import { I as IEdgeRemoteStorage, U as UpstashRedisOptions, a as CloudflareKVNamespace, d as CloudflareDOStorage } from '../hono-DuNvciyq.js';
|
|
2
|
+
export { C as CachedEdgeHttpResponse, e as CloudflareR2Bucket, f as CloudflareR2Object, E as EdgeCacheOptions, g as EdgeCacheService, i as EdgeExportSnapshotOptions, j as EdgeGetOptions, k as EdgeHydrateOptions, l as EdgeSnapshotPayload, m as EdgeSnapshotSource, H as HonoEdgeCacheOptions, n as IEdgeBloomFilter, b as buildEdgeDeterministicKey, c as computeEdgeETag, h as honoEdgeCache } from '../hono-DuNvciyq.js';
|
|
3
3
|
export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from '../murmur3-CMGw9PbV.js';
|
|
4
|
-
import '../types-
|
|
4
|
+
import '../types-5HXqBfAf.js';
|
|
5
5
|
import 'crypto';
|
|
6
6
|
|
|
7
7
|
type WebCryptoMode = 'aes-256-gcm' | 'aes-128-gcm';
|
package/dist/edge/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildEdgeDeterministicKey,
|
|
3
|
-
computeEdgeETag,
|
|
4
|
-
honoEdgeCache
|
|
5
|
-
} from "../chunk-ZTSWCFYO.js";
|
|
6
1
|
import {
|
|
7
2
|
Murmur3BloomFilter,
|
|
8
3
|
murmur3_32
|
|
@@ -10,10 +5,18 @@ import {
|
|
|
10
5
|
import {
|
|
11
6
|
WasmBloomFilter,
|
|
12
7
|
base64ToUint8Array,
|
|
8
|
+
isChildTag,
|
|
9
|
+
isWildcardTag,
|
|
10
|
+
matchesTagPattern,
|
|
13
11
|
uint8ArrayToBase64,
|
|
14
12
|
uint8ArrayToUtf8,
|
|
15
13
|
utf8ToUint8Array
|
|
16
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-2AJKEQMZ.js";
|
|
15
|
+
import {
|
|
16
|
+
buildEdgeDeterministicKey,
|
|
17
|
+
computeEdgeETag,
|
|
18
|
+
honoEdgeCache
|
|
19
|
+
} from "../chunk-IITRFWHY.js";
|
|
17
20
|
|
|
18
21
|
// src/edge/crypto.ts
|
|
19
22
|
var PREFIX_256 = "enc:v1:";
|
|
@@ -458,11 +461,12 @@ var EdgeCacheService = class {
|
|
|
458
461
|
const nsKey = this.nk(key);
|
|
459
462
|
const resolvedTtl = ttlSeconds ?? this.defaultTtl;
|
|
460
463
|
const now = Date.now();
|
|
461
|
-
const
|
|
464
|
+
const optObj = Array.isArray(options) ? { tags: options } : options;
|
|
465
|
+
const swrSeconds = optObj?.swr ?? 0;
|
|
462
466
|
try {
|
|
463
467
|
let activeTagVersions;
|
|
464
|
-
if (
|
|
465
|
-
activeTagVersions = await this._batchGetTagVersions(
|
|
468
|
+
if (optObj?.tags?.length) {
|
|
469
|
+
activeTagVersions = await this._batchGetTagVersions(optObj.tags);
|
|
466
470
|
}
|
|
467
471
|
const serialized = JSON.stringify(value);
|
|
468
472
|
const bytes = this._estimateBytes(nsKey, serialized);
|
|
@@ -474,13 +478,13 @@ var EdgeCacheService = class {
|
|
|
474
478
|
bytes,
|
|
475
479
|
expiresAt: now + resolvedTtl * 1e3,
|
|
476
480
|
staleUntil: now + (resolvedTtl + swrSeconds) * 1e3,
|
|
477
|
-
tags:
|
|
481
|
+
tags: optObj?.tags,
|
|
478
482
|
tagVersions: activeTagVersions
|
|
479
483
|
};
|
|
480
484
|
this.l1.set(nsKey, entry);
|
|
481
485
|
this.currentBytes += bytes;
|
|
482
|
-
if (
|
|
483
|
-
for (const tag of
|
|
486
|
+
if (optObj?.tags) {
|
|
487
|
+
for (const tag of optObj.tags) {
|
|
484
488
|
let s = this.tagIndex.get(tag);
|
|
485
489
|
if (!s) {
|
|
486
490
|
s = /* @__PURE__ */ new Set();
|
|
@@ -528,10 +532,33 @@ var EdgeCacheService = class {
|
|
|
528
532
|
/**
|
|
529
533
|
* Invalidates all cached entries associated with a tag.
|
|
530
534
|
*/
|
|
531
|
-
async invalidateTag(tag) {
|
|
535
|
+
async invalidateTag(tag, opts) {
|
|
532
536
|
const span = this._startSpan("tricache.invalidate_tag");
|
|
533
537
|
span.setAttribute("cache.tag", tag);
|
|
538
|
+
if (opts?.cascade) span.setAttribute("cache.cascade", true);
|
|
534
539
|
try {
|
|
540
|
+
const isPattern = isWildcardTag(tag);
|
|
541
|
+
const shouldCascade = Boolean(opts?.cascade);
|
|
542
|
+
if (isPattern || shouldCascade) {
|
|
543
|
+
const matched = /* @__PURE__ */ new Set();
|
|
544
|
+
const tagMatches = (t) => {
|
|
545
|
+
if (t === tag) return true;
|
|
546
|
+
if (isPattern && matchesTagPattern(tag, t)) return true;
|
|
547
|
+
if (shouldCascade && isChildTag(tag, t, ":")) return true;
|
|
548
|
+
return false;
|
|
549
|
+
};
|
|
550
|
+
for (const t of this.tagIndex.keys()) {
|
|
551
|
+
if (tagMatches(t)) matched.add(t);
|
|
552
|
+
}
|
|
553
|
+
for (const t of this.tagVersionCache.keys()) {
|
|
554
|
+
if (tagMatches(t)) matched.add(t);
|
|
555
|
+
}
|
|
556
|
+
if (shouldCascade && !isPattern) matched.add(tag);
|
|
557
|
+
for (const t of matched) {
|
|
558
|
+
await this.invalidateTag(t);
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
535
562
|
let newVer = 1;
|
|
536
563
|
if (this.remoteStorage) {
|
|
537
564
|
try {
|
|
@@ -615,9 +642,10 @@ var EdgeCacheService = class {
|
|
|
615
642
|
span.setAttribute("cache.misses", missKeys.length);
|
|
616
643
|
if (missKeys.length > 0 && fetchFn) {
|
|
617
644
|
const fetchedMap = await fetchFn(missKeys);
|
|
645
|
+
const isMap = fetchedMap instanceof Map;
|
|
618
646
|
for (let j = 0; j < missKeys.length; j++) {
|
|
619
647
|
const k = missKeys[j];
|
|
620
|
-
const fetchedVal = fetchedMap[k];
|
|
648
|
+
const fetchedVal = isMap ? fetchedMap.get(k) : fetchedMap[k];
|
|
621
649
|
if (fetchedVal !== void 0) {
|
|
622
650
|
results[missIndices[j]] = fetchedVal;
|
|
623
651
|
await this.set(k, fetchedVal, ttlSeconds);
|