tricache 1.0.0 → 1.0.2
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 +36 -28
- package/dist/{cache-service-pJ-nFcVj.d.ts → cache-service-B108FzER.d.ts} +63 -3
- package/dist/cache-service-CWI4jkS7.d.cts +963 -0
- package/dist/{cache-service-26GCO3UU.js → cache-service-GYPZFB7O.js} +2 -2
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-2AJKEQMZ.js → chunk-H4GFLQ26.js} +7 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/chunk-OYDU3SMI.js +89 -0
- package/dist/{chunk-VXFTFZ5N.js → chunk-VNRDL5RA.js} +117 -138
- package/dist/{chunk-7SZSQS55.js → chunk-WYF7NOAT.js} +1831 -759
- package/dist/cli.cjs +1757 -777
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +27 -6
- package/dist/dashboard/index.cjs +111 -29
- package/dist/dashboard/index.d.cts +185 -0
- package/dist/dashboard/index.d.ts +5 -3
- package/dist/dashboard/index.js +1 -1
- package/dist/drizzle/index.cjs +1757 -773
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +280 -153
- package/dist/edge/index.d.cts +127 -0
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +254 -147
- package/dist/hono/index.cjs +1805 -793
- package/dist/hono/index.d.cts +93 -0
- package/dist/hono/index.d.ts +7 -5
- package/dist/hono/index.js +16 -9
- package/dist/{hono-DuNvciyq.d.ts → hono-3rDMYVtY.d.ts} +23 -3
- package/dist/hono-C886ok3X.d.cts +391 -0
- package/dist/http/index.cjs +1946 -842
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +137 -57
- package/dist/index.cjs +2073 -937
- package/dist/index.d.cts +1006 -0
- package/dist/index.d.ts +40 -8
- package/dist/index.js +8 -8
- package/dist/murmur3-CMGw9PbV.d.cts +98 -0
- package/dist/nestjs/index.cjs +1849 -806
- package/dist/nestjs/index.d.cts +285 -0
- package/dist/nestjs/index.d.ts +103 -30
- package/dist/nestjs/index.js +115 -32
- package/dist/next/index.cjs +1913 -887
- package/dist/next/index.d.cts +232 -0
- package/dist/next/index.d.ts +33 -11
- package/dist/next/index.js +174 -107
- package/dist/prisma/index.cjs +11 -1
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +11 -1
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/{types-5HXqBfAf.d.ts → types-BA4pz1A0.d.cts} +26 -9
- package/dist/types-BA4pz1A0.d.ts +1519 -0
- package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
- package/dist/utils-Bvzn-rKS.d.ts +29 -0
- package/package.json +96 -36
- package/src/adapters/auto-pipeliner.ts +107 -24
- package/src/adapters/node-redis.ts +123 -25
- package/src/cache-service.ts +1238 -659
- package/src/cli.ts +24 -6
- package/src/cross-region.ts +21 -3
- package/src/dashboard/handler.ts +26 -6
- package/src/dashboard/html.ts +35 -10
- package/src/dashboard/index.ts +35 -13
- package/src/dashboard/types.ts +3 -1
- package/src/disk-tier.ts +171 -65
- package/src/edge/cache.ts +202 -129
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +2 -0
- package/src/hono/index.ts +19 -9
- package/src/http/express.ts +110 -26
- package/src/http/fastify.ts +38 -28
- package/src/http/utils.ts +54 -20
- package/src/ipc-telemetry.ts +35 -9
- package/src/nestjs/decorators.ts +1 -1
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +13 -11
- package/src/nestjs/tricache.store.ts +51 -20
- package/src/nestjs/types.ts +29 -15
- package/src/next/cache-handler.ts +132 -57
- package/src/next/index.ts +1 -0
- package/src/next/isr-handler.ts +1 -4
- package/src/next/types.ts +21 -0
- package/src/prisma/index.ts +12 -1
- package/src/smart-memory-cache.ts +65 -27
- package/src/types.ts +27 -2
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -0
- package/src/utils/redis-slot.ts +13 -0
- package/src/wasm/bloom-filter-wasm.ts +9 -4
- package/src/worker-pool.ts +17 -8
- package/src/wtiny-lfu.ts +20 -6
- package/dist/chunk-BQRURGGD.js +0 -60
package/dist/edge/index.cjs
CHANGED
|
@@ -210,9 +210,12 @@ var WebCryptoEncryption = class {
|
|
|
210
210
|
var BLOOM_WASM_BASE64 = "AGFzbQEAAAABIwdgAn9/AX9gAX8AYAF/AX9gA39/fwF/YAJ/fwBgAABgAAF/AwoJAAABAgMEAAUGBQMBAAEGDQJ/AEGgjQYLfwBBBwsHMwUGbWVtb3J5AgADYWRkAAUMbWlnaHRDb250YWluAAYFcmVzZXQABwljb3VudEJpdHMACAqtAwk/AQJ/QcW78oh4IQIgACABaiEDAkADQCAAIANPDQEgAiAALQAAcyECIAJBk4OACGwhAiAAQQFqIQAMAAsLIAILOAECf0GFKiECIAAgAWohAwJAA0AgACADTw0BIAJBBXQgAmogAC0AAGohAiAAQQFqIQAMAAsLIAILHgEBfyAAQQN2IQEgASABLQAAQQEgAEEHcXRyOgAACxYAIABBA3YtAABBASAAQQdxdHFBAEcLDQAgACACIAFsaiMAcAs4AQN/IAAgARAAIQIgACABEAEhA0EAIQQCQANAIAQjAU8NASACIAMgBBAEEAIgBEEBaiEEDAALCwtBAQN/IAAgARAAIQIgACABEAEhA0EAIQQCQANAIAQjAU8NASACIAMgBBAEEANFBEBBAA8LIARBAWohBAwACwtBAQsnAQF/QQAhAAJAA0AgAEHU4QBPDQEgAEEANgIAIABBBGohAAwACwsLSwEDf0EAIQBBACEBAkADQCAAQdThAE8NASAALQAAIQICQANAIAJFDQEgAUEBaiEBIAIgAkEBa3EhAgwACwsgAEEBaiEADAALCyABCw==";
|
|
211
211
|
var KEY_STAGING_OFFSET = 2e4;
|
|
212
212
|
var MAX_KEY_BYTES = 512;
|
|
213
|
-
var
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
var bloomWasmModule;
|
|
214
|
+
function getBloomWasmModule() {
|
|
215
|
+
return bloomWasmModule ??= new WebAssembly.Module(
|
|
216
|
+
base64ToUint8Array(BLOOM_WASM_BASE64)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
216
219
|
var WasmBloomFilter = class {
|
|
217
220
|
exports;
|
|
218
221
|
mem;
|
|
@@ -224,7 +227,7 @@ var WasmBloomFilter = class {
|
|
|
224
227
|
/** Tracks total add() calls so we know when phantom bits have saturated the filter. */
|
|
225
228
|
_insertionCount = 0;
|
|
226
229
|
constructor() {
|
|
227
|
-
const instance = new WebAssembly.Instance(
|
|
230
|
+
const instance = new WebAssembly.Instance(getBloomWasmModule(), {});
|
|
228
231
|
this.exports = instance.exports;
|
|
229
232
|
this.mem = new Uint8Array(this.exports.memory.buffer);
|
|
230
233
|
this.stagingTarget = new Uint8Array(this.exports.memory.buffer, KEY_STAGING_OFFSET, MAX_KEY_BYTES);
|
|
@@ -438,7 +441,8 @@ function isChildTag(parentTag, candidateTag, delimiter = ":") {
|
|
|
438
441
|
}
|
|
439
442
|
|
|
440
443
|
// src/edge/cache.ts
|
|
441
|
-
var
|
|
444
|
+
var NAMESPACE_TAG = "_tricache_namespace_";
|
|
445
|
+
var EdgeCacheService = class _EdgeCacheService {
|
|
442
446
|
maxKeys;
|
|
443
447
|
maxBytes;
|
|
444
448
|
defaultTtl;
|
|
@@ -447,6 +451,10 @@ var EdgeCacheService = class {
|
|
|
447
451
|
enc;
|
|
448
452
|
tracer;
|
|
449
453
|
bloomFilter;
|
|
454
|
+
bloomAuthoritative;
|
|
455
|
+
globalEpoch = 0;
|
|
456
|
+
lastGlobalMutationAt = 0;
|
|
457
|
+
keyEpochs = /* @__PURE__ */ new Map();
|
|
450
458
|
// L1 Dual-bounded LRU
|
|
451
459
|
l1 = /* @__PURE__ */ new Map();
|
|
452
460
|
currentBytes = 0;
|
|
@@ -455,6 +463,7 @@ var EdgeCacheService = class {
|
|
|
455
463
|
// Tag indexing for edge
|
|
456
464
|
tagIndex = /* @__PURE__ */ new Map();
|
|
457
465
|
// Tag version in-isolate cache with 800ms micro-TTL (prevents HTTP fetch amplification on L1 hits)
|
|
466
|
+
static MAX_TAG_VERSION_CACHE = 1e4;
|
|
458
467
|
tagVersionCache = /* @__PURE__ */ new Map();
|
|
459
468
|
tagVersionTtlMs = 800;
|
|
460
469
|
constructor(options) {
|
|
@@ -465,6 +474,8 @@ var EdgeCacheService = class {
|
|
|
465
474
|
this.remoteStorage = options?.remoteStorage ?? null;
|
|
466
475
|
this.tracer = options?.tracer ?? null;
|
|
467
476
|
this.enc = new WebCryptoEncryption(options?.encryption);
|
|
477
|
+
this.bloomAuthoritative = options?.bloomFilterAuthoritative ?? false;
|
|
478
|
+
if (!Number.isInteger(this.maxKeys) || this.maxKeys < 0 || !Number.isFinite(this.maxBytes) || this.maxBytes < 0 || !Number.isFinite(this.defaultTtl) || this.defaultTtl < 0) throw new Error("Edge cache limits and TTL must be finite non-negative values");
|
|
468
479
|
if (options?.bloomFilter === true) {
|
|
469
480
|
try {
|
|
470
481
|
this.bloomFilter = new WasmBloomFilter();
|
|
@@ -489,6 +500,66 @@ var EdgeCacheService = class {
|
|
|
489
500
|
_estimateBytes(key, serialized) {
|
|
490
501
|
return (key.length + serialized.length) * 2 + 64;
|
|
491
502
|
}
|
|
503
|
+
fence(key) {
|
|
504
|
+
return `${this.globalEpoch}:${this.keyEpochs.get(key) ?? 0}`;
|
|
505
|
+
}
|
|
506
|
+
mutate(key) {
|
|
507
|
+
this.keyEpochs.set(key, (this.keyEpochs.get(key) ?? 0) + 1);
|
|
508
|
+
this.inflight.delete(key);
|
|
509
|
+
if (this.keyEpochs.size > 5e4) {
|
|
510
|
+
this.globalEpoch++;
|
|
511
|
+
this.keyEpochs.clear();
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
invalidateWork() {
|
|
515
|
+
this.globalEpoch++;
|
|
516
|
+
this.lastGlobalMutationAt = Date.now();
|
|
517
|
+
this.inflight.clear();
|
|
518
|
+
}
|
|
519
|
+
storeL1(key, entry) {
|
|
520
|
+
this._deleteL1(key);
|
|
521
|
+
if (entry.bytes > this.maxBytes || this.maxKeys === 0 || entry.staleUntil <= Date.now()) return false;
|
|
522
|
+
this._evictIfNeeded(entry.bytes);
|
|
523
|
+
this.l1.set(key, entry);
|
|
524
|
+
this.currentBytes += entry.bytes;
|
|
525
|
+
for (const tag of entry.tags ?? []) {
|
|
526
|
+
const members = this.tagIndex.get(tag) ?? /* @__PURE__ */ new Set();
|
|
527
|
+
members.add(key);
|
|
528
|
+
this.tagIndex.set(tag, members);
|
|
529
|
+
}
|
|
530
|
+
this.bloomFilter?.add(key);
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
async commit(key, value, ttl, options, versions, epoch) {
|
|
534
|
+
const namespaced = this.nk(key);
|
|
535
|
+
if (this.fence(namespaced) !== epoch) return;
|
|
536
|
+
const serialized = JSON.stringify(value);
|
|
537
|
+
if (serialized === void 0) return;
|
|
538
|
+
const now = Date.now();
|
|
539
|
+
const entry = {
|
|
540
|
+
value,
|
|
541
|
+
serialized,
|
|
542
|
+
bytes: this._estimateBytes(namespaced, serialized),
|
|
543
|
+
expiresAt: now + ttl * 1e3,
|
|
544
|
+
staleUntil: now + (ttl + (options?.swr ?? 0)) * 1e3,
|
|
545
|
+
tags: options?.tags ? [...new Set(options.tags)] : void 0,
|
|
546
|
+
tagVersions: versions
|
|
547
|
+
};
|
|
548
|
+
this.storeL1(namespaced, entry);
|
|
549
|
+
if (this.remoteStorage) {
|
|
550
|
+
const envelope = JSON.stringify({
|
|
551
|
+
__t_edge: 2,
|
|
552
|
+
__t_val: value,
|
|
553
|
+
__t_tv: versions,
|
|
554
|
+
__t_exp: entry.expiresAt,
|
|
555
|
+
__t_stale: entry.staleUntil,
|
|
556
|
+
__t_tags: entry.tags
|
|
557
|
+
});
|
|
558
|
+
const payload = this.enc.isEnabled ? await this.enc.encrypt(envelope) : envelope;
|
|
559
|
+
if (this.fence(namespaced) !== epoch) return;
|
|
560
|
+
await this.remoteStorage.set(namespaced, payload, ttl + (options?.swr ?? 0));
|
|
561
|
+
}
|
|
562
|
+
}
|
|
492
563
|
_evictIfNeeded(newBytes) {
|
|
493
564
|
while (this.currentBytes + newBytes > this.maxBytes && this.l1.size > 0) {
|
|
494
565
|
const oldestKey = this.l1.keys().next().value;
|
|
@@ -537,6 +608,22 @@ var EdgeCacheService = class {
|
|
|
537
608
|
}
|
|
538
609
|
};
|
|
539
610
|
}
|
|
611
|
+
_setTagVersionCache(tag, version, expiresAt) {
|
|
612
|
+
if (this.tagVersionCache.size >= _EdgeCacheService.MAX_TAG_VERSION_CACHE && !this.tagVersionCache.has(tag)) {
|
|
613
|
+
const now = Date.now();
|
|
614
|
+
for (const [k, v] of this.tagVersionCache) {
|
|
615
|
+
if (v.expiresAt <= now) {
|
|
616
|
+
this.tagVersionCache.delete(k);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (this.tagVersionCache.size >= _EdgeCacheService.MAX_TAG_VERSION_CACHE) {
|
|
620
|
+
const oldestKey = this.tagVersionCache.keys().next().value;
|
|
621
|
+
if (oldestKey !== void 0) this.tagVersionCache.delete(oldestKey);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const known = this.tagVersionCache.get(tag)?.version ?? 0;
|
|
625
|
+
this.tagVersionCache.set(tag, { version: Math.max(known, version), expiresAt });
|
|
626
|
+
}
|
|
540
627
|
async _getTagVersion(tag) {
|
|
541
628
|
const cached = this.tagVersionCache.get(tag);
|
|
542
629
|
const now = Date.now();
|
|
@@ -558,12 +645,12 @@ var EdgeCacheService = class {
|
|
|
558
645
|
} else {
|
|
559
646
|
version = cached?.version ?? 1;
|
|
560
647
|
}
|
|
561
|
-
this.
|
|
562
|
-
return version;
|
|
648
|
+
this._setTagVersionCache(tag, version, now + this.tagVersionTtlMs);
|
|
649
|
+
return this.tagVersionCache.get(tag)?.version ?? version;
|
|
563
650
|
}
|
|
564
651
|
async _batchGetTagVersions(tags) {
|
|
565
652
|
const now = Date.now();
|
|
566
|
-
const result =
|
|
653
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
567
654
|
const missingTags = [];
|
|
568
655
|
for (const t of tags) {
|
|
569
656
|
const c = this.tagVersionCache.get(t);
|
|
@@ -581,8 +668,8 @@ var EdgeCacheService = class {
|
|
|
581
668
|
for (let i = 0; i < missingTags.length; i++) {
|
|
582
669
|
const t = missingTags[i];
|
|
583
670
|
const v = remoteVersions[this.nk(t)] ?? remoteVersions[t] ?? 1;
|
|
584
|
-
result[t] = v;
|
|
585
|
-
this.
|
|
671
|
+
result[t] = Math.max(this.tagVersionCache.get(t)?.version ?? 0, v);
|
|
672
|
+
this._setTagVersionCache(t, v, now + this.tagVersionTtlMs);
|
|
586
673
|
}
|
|
587
674
|
} else {
|
|
588
675
|
await Promise.all(missingTags.map(async (t) => {
|
|
@@ -609,7 +696,7 @@ var EdgeCacheService = class {
|
|
|
609
696
|
const span = this._startSpan("tricache.get");
|
|
610
697
|
span.setAttribute("cache.key", key);
|
|
611
698
|
const nsKey = this.nk(key);
|
|
612
|
-
|
|
699
|
+
let now = Date.now();
|
|
613
700
|
const resolvedTtl = ttlSeconds ?? this.defaultTtl;
|
|
614
701
|
try {
|
|
615
702
|
const l1Entry = this.l1.get(nsKey);
|
|
@@ -625,6 +712,7 @@ var EdgeCacheService = class {
|
|
|
625
712
|
}
|
|
626
713
|
}
|
|
627
714
|
}
|
|
715
|
+
now = Date.now();
|
|
628
716
|
if (isTagStale) {
|
|
629
717
|
this._deleteL1(nsKey);
|
|
630
718
|
} else {
|
|
@@ -636,85 +724,115 @@ var EdgeCacheService = class {
|
|
|
636
724
|
span.setAttribute("cache.hit_tier", "l1");
|
|
637
725
|
return l1Entry.value;
|
|
638
726
|
}
|
|
639
|
-
if (l1Entry.staleUntil > now && fetchFn) {
|
|
727
|
+
if (l1Entry.staleUntil > now && fetchFn && (options?.swr ?? 0) > 0) {
|
|
640
728
|
span.setAttribute("cache.hit", true);
|
|
641
729
|
span.setAttribute("cache.item.tier", "memory");
|
|
642
730
|
span.setAttribute("cache.hit_tier", "l1");
|
|
643
731
|
span.setAttribute("cache.stale", true);
|
|
644
|
-
const revalPromise = this._revalidate(key, fetchFn, resolvedTtl, options);
|
|
732
|
+
const revalPromise = this._revalidate(key, fetchFn, resolvedTtl, { ...options, tags: options?.tags ?? l1Entry.tags });
|
|
645
733
|
if (options?.ctx?.waitUntil) {
|
|
646
734
|
options.ctx.waitUntil(revalPromise);
|
|
647
735
|
}
|
|
648
736
|
return l1Entry.value;
|
|
649
737
|
}
|
|
650
|
-
this._deleteL1(nsKey);
|
|
738
|
+
if (l1Entry.staleUntil <= now) this._deleteL1(nsKey);
|
|
651
739
|
}
|
|
652
740
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
741
|
+
const existing = this.inflight.get(nsKey);
|
|
742
|
+
if (existing) {
|
|
743
|
+
span.setAttribute("cache.stampede_coalesced", true);
|
|
744
|
+
return await existing;
|
|
745
|
+
}
|
|
746
|
+
const epoch = this.fence(nsKey);
|
|
747
|
+
const execution = Promise.resolve().then(async () => {
|
|
748
|
+
try {
|
|
749
|
+
if (this.remoteStorage) {
|
|
750
|
+
if (this.bloomAuthoritative && this.bloomFilter && !this.bloomFilter.mightContain(nsKey)) {
|
|
751
|
+
span.setAttribute("cache.bloom.filtered", true);
|
|
752
|
+
} else {
|
|
753
|
+
try {
|
|
754
|
+
const rawRemote = await this.remoteStorage.get(nsKey);
|
|
755
|
+
if (rawRemote !== null) {
|
|
756
|
+
const plain = this.enc.isEnabled ? await this.enc.decrypt(rawRemote) : rawRemote;
|
|
757
|
+
const parsedJson = JSON.parse(plain);
|
|
758
|
+
let parsed;
|
|
759
|
+
let activeTagVersions;
|
|
760
|
+
let isStaleRemote = false;
|
|
761
|
+
if (parsedJson && typeof parsedJson === "object" && "__t_val" in parsedJson && "__t_tv" in parsedJson) {
|
|
762
|
+
parsed = parsedJson.__t_val;
|
|
763
|
+
activeTagVersions = parsedJson.__t_tv;
|
|
764
|
+
if (!activeTagVersions || typeof activeTagVersions !== "object" || Array.isArray(activeTagVersions) || Object.values(activeTagVersions).some((version) => !Number.isSafeInteger(version) || version < 0)) throw new Error("Invalid remote tag versions");
|
|
765
|
+
const tagNames = Object.keys(activeTagVersions);
|
|
766
|
+
const currentVers = await this._batchGetTagVersions(tagNames);
|
|
767
|
+
for (const tag of tagNames) {
|
|
768
|
+
if (currentVers[tag] > activeTagVersions[tag]) {
|
|
769
|
+
isStaleRemote = true;
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
parsed = parsedJson;
|
|
775
|
+
}
|
|
776
|
+
if (!isStaleRemote) {
|
|
777
|
+
const freshUntil = Number(parsedJson?.__t_exp);
|
|
778
|
+
const staleUntil = Number(parsedJson?.__t_stale);
|
|
779
|
+
const versioned = parsedJson?.__t_edge === 2 && Number.isFinite(freshUntil) && Number.isFinite(staleUntil) && staleUntil >= freshUntil;
|
|
780
|
+
if (versioned && (staleUntil <= Date.now() || freshUntil <= Date.now() && (!(options?.swr ?? 0) || !fetchFn))) {
|
|
781
|
+
isStaleRemote = true;
|
|
782
|
+
} else {
|
|
783
|
+
if (versioned && this.fence(nsKey) === epoch) {
|
|
784
|
+
const serialized = JSON.stringify(parsed);
|
|
785
|
+
const tags2 = Array.isArray(parsedJson.__t_tags) ? parsedJson.__t_tags : Object.keys(activeTagVersions ?? {}).filter((tag) => tag !== NAMESPACE_TAG);
|
|
786
|
+
this.storeL1(nsKey, {
|
|
787
|
+
value: parsed,
|
|
788
|
+
serialized,
|
|
789
|
+
bytes: this._estimateBytes(nsKey, serialized),
|
|
790
|
+
expiresAt: freshUntil,
|
|
791
|
+
staleUntil,
|
|
792
|
+
tags: tags2,
|
|
793
|
+
tagVersions: activeTagVersions
|
|
794
|
+
});
|
|
795
|
+
if (freshUntil <= Date.now() && fetchFn) {
|
|
796
|
+
const refresh = execution.then(() => this._revalidate(key, fetchFn, resolvedTtl, { ...options, tags: tags2 }));
|
|
797
|
+
options?.ctx?.waitUntil(refresh);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
span.setAttribute("cache.hit", true);
|
|
801
|
+
span.setAttribute("cache.item.tier", "remote");
|
|
802
|
+
span.setAttribute("cache.hit_tier", "l2");
|
|
803
|
+
return parsed;
|
|
804
|
+
}
|
|
674
805
|
}
|
|
675
806
|
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
if (!isStaleRemote) {
|
|
680
|
-
await this.set(key, parsed, resolvedTtl, options);
|
|
681
|
-
span.setAttribute("cache.hit", true);
|
|
682
|
-
span.setAttribute("cache.item.tier", "remote");
|
|
683
|
-
span.setAttribute("cache.hit_tier", "l2");
|
|
684
|
-
return parsed;
|
|
807
|
+
} catch (remoteErr) {
|
|
808
|
+
span.recordException?.(remoteErr);
|
|
685
809
|
}
|
|
686
810
|
}
|
|
687
|
-
} catch (remoteErr) {
|
|
688
|
-
span.recordException?.(remoteErr);
|
|
689
811
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
span.setAttribute("cache.hit_tier", "miss");
|
|
695
|
-
return null;
|
|
696
|
-
}
|
|
697
|
-
let inflightPromise = this.inflight.get(nsKey);
|
|
698
|
-
let coalesced = false;
|
|
699
|
-
if (inflightPromise) {
|
|
700
|
-
coalesced = true;
|
|
701
|
-
} else {
|
|
702
|
-
inflightPromise = (async () => {
|
|
703
|
-
try {
|
|
704
|
-
const fresh = await fetchFn();
|
|
705
|
-
await this.set(key, fresh, resolvedTtl, options);
|
|
706
|
-
return fresh;
|
|
707
|
-
} finally {
|
|
708
|
-
this.inflight.delete(nsKey);
|
|
812
|
+
if (!fetchFn) {
|
|
813
|
+
span.setAttribute("cache.hit", false);
|
|
814
|
+
span.setAttribute("cache.hit_tier", "miss");
|
|
815
|
+
return null;
|
|
709
816
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
817
|
+
const tags = [.../* @__PURE__ */ new Set([NAMESPACE_TAG, ...options?.tags ?? []])];
|
|
818
|
+
const versions = await this._batchGetTagVersions(tags);
|
|
819
|
+
const fresh = await fetchFn();
|
|
820
|
+
const current = await this._batchGetTagVersions(tags);
|
|
821
|
+
if (this.fence(nsKey) === epoch && tags.every((tag) => current[tag] === versions[tag])) {
|
|
822
|
+
try {
|
|
823
|
+
await this.commit(key, fresh, resolvedTtl, options, versions, epoch);
|
|
824
|
+
} catch (error) {
|
|
825
|
+
span.recordException?.(error);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
span.setAttribute("cache.hit", false).setAttribute("cache.hit_tier", "miss");
|
|
829
|
+
return fresh;
|
|
830
|
+
} finally {
|
|
831
|
+
if (this.inflight.get(nsKey) === execution) this.inflight.delete(nsKey);
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
this.inflight.set(nsKey, execution);
|
|
835
|
+
return await execution;
|
|
718
836
|
} catch (err) {
|
|
719
837
|
span.setStatus({ code: 2, message: err instanceof Error ? err.message : String(err) });
|
|
720
838
|
span.recordException?.(err);
|
|
@@ -726,15 +844,19 @@ var EdgeCacheService = class {
|
|
|
726
844
|
async _revalidate(key, fetchFn, ttl, options) {
|
|
727
845
|
const nsKey = this.nk(key);
|
|
728
846
|
if (this.inflight.has(nsKey)) return;
|
|
729
|
-
const
|
|
847
|
+
const epoch = this.fence(nsKey);
|
|
848
|
+
const task = Promise.resolve().then(async () => {
|
|
730
849
|
try {
|
|
850
|
+
const tags = [.../* @__PURE__ */ new Set([NAMESPACE_TAG, ...options?.tags ?? []])];
|
|
851
|
+
const versions = await this._batchGetTagVersions(tags);
|
|
731
852
|
const fresh = await fetchFn();
|
|
732
|
-
await this.
|
|
853
|
+
const current = await this._batchGetTagVersions(tags);
|
|
854
|
+
if (this.fence(nsKey) === epoch && tags.every((tag) => current[tag] === versions[tag])) await this.commit(key, fresh, ttl, options, versions, epoch);
|
|
733
855
|
} catch {
|
|
734
856
|
} finally {
|
|
735
|
-
this.inflight.delete(nsKey);
|
|
857
|
+
if (this.inflight.get(nsKey) === task) this.inflight.delete(nsKey);
|
|
736
858
|
}
|
|
737
|
-
})
|
|
859
|
+
});
|
|
738
860
|
this.inflight.set(nsKey, task);
|
|
739
861
|
await task;
|
|
740
862
|
}
|
|
@@ -745,48 +867,15 @@ var EdgeCacheService = class {
|
|
|
745
867
|
const span = this._startSpan("tricache.set");
|
|
746
868
|
span.setAttribute("cache.key", key);
|
|
747
869
|
const nsKey = this.nk(key);
|
|
870
|
+
this.mutate(nsKey);
|
|
871
|
+
const epoch = this.fence(nsKey);
|
|
748
872
|
const resolvedTtl = ttlSeconds ?? this.defaultTtl;
|
|
749
|
-
const now = Date.now();
|
|
750
873
|
const optObj = Array.isArray(options) ? { tags: options } : options;
|
|
751
874
|
const swrSeconds = optObj?.swr ?? 0;
|
|
752
875
|
try {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
const serialized = JSON.stringify(value);
|
|
758
|
-
const bytes = this._estimateBytes(nsKey, serialized);
|
|
759
|
-
this._deleteL1(nsKey);
|
|
760
|
-
this._evictIfNeeded(bytes);
|
|
761
|
-
const entry = {
|
|
762
|
-
value,
|
|
763
|
-
serialized,
|
|
764
|
-
bytes,
|
|
765
|
-
expiresAt: now + resolvedTtl * 1e3,
|
|
766
|
-
staleUntil: now + (resolvedTtl + swrSeconds) * 1e3,
|
|
767
|
-
tags: optObj?.tags,
|
|
768
|
-
tagVersions: activeTagVersions
|
|
769
|
-
};
|
|
770
|
-
this.l1.set(nsKey, entry);
|
|
771
|
-
this.currentBytes += bytes;
|
|
772
|
-
if (optObj?.tags) {
|
|
773
|
-
for (const tag of optObj.tags) {
|
|
774
|
-
let s = this.tagIndex.get(tag);
|
|
775
|
-
if (!s) {
|
|
776
|
-
s = /* @__PURE__ */ new Set();
|
|
777
|
-
this.tagIndex.set(tag, s);
|
|
778
|
-
}
|
|
779
|
-
s.add(nsKey);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (this.remoteStorage) {
|
|
783
|
-
const toStoreRaw = activeTagVersions ? JSON.stringify({ __t_val: value, __t_tv: activeTagVersions }) : serialized;
|
|
784
|
-
const payloadToStore = this.enc.isEnabled ? await this.enc.encrypt(toStoreRaw) : toStoreRaw;
|
|
785
|
-
await this.remoteStorage.set(nsKey, payloadToStore, resolvedTtl + swrSeconds);
|
|
786
|
-
}
|
|
787
|
-
if (this.bloomFilter) {
|
|
788
|
-
this.bloomFilter.add(nsKey);
|
|
789
|
-
}
|
|
876
|
+
if (!Number.isFinite(resolvedTtl) || resolvedTtl < 0 || !Number.isFinite(swrSeconds) || swrSeconds < 0) throw new Error("Edge TTL and SWR must be finite non-negative values");
|
|
877
|
+
const versions = await this._batchGetTagVersions([.../* @__PURE__ */ new Set([NAMESPACE_TAG, ...optObj?.tags ?? []])]);
|
|
878
|
+
await this.commit(key, value, resolvedTtl, optObj, versions, epoch);
|
|
790
879
|
} catch (err) {
|
|
791
880
|
span.setStatus({ code: 2, message: err instanceof Error ? err.message : String(err) });
|
|
792
881
|
span.recordException?.(err);
|
|
@@ -803,6 +892,7 @@ var EdgeCacheService = class {
|
|
|
803
892
|
span.setAttribute("cache.key", key);
|
|
804
893
|
const nsKey = this.nk(key);
|
|
805
894
|
try {
|
|
895
|
+
this.mutate(nsKey);
|
|
806
896
|
this._deleteL1(nsKey);
|
|
807
897
|
if (this.remoteStorage) {
|
|
808
898
|
await this.remoteStorage.delete(nsKey);
|
|
@@ -815,6 +905,44 @@ var EdgeCacheService = class {
|
|
|
815
905
|
span.end();
|
|
816
906
|
}
|
|
817
907
|
}
|
|
908
|
+
/**
|
|
909
|
+
* Executes invalidation for a single already-resolved concrete tag without
|
|
910
|
+
* re-entering wildcard/cascade resolution.
|
|
911
|
+
*/
|
|
912
|
+
async _invalidateConcreteTag(tag) {
|
|
913
|
+
this.invalidateWork();
|
|
914
|
+
const previous = this.tagVersionCache.get(tag)?.version ?? 1;
|
|
915
|
+
let newVer = 1;
|
|
916
|
+
if (this.remoteStorage) {
|
|
917
|
+
try {
|
|
918
|
+
if (typeof this.remoteStorage.incrementTagVersion === "function") {
|
|
919
|
+
newVer = await this.remoteStorage.incrementTagVersion(this.nk(tag));
|
|
920
|
+
if (newVer <= previous) newVer = await this.remoteStorage.incrementTagVersion(this.nk(tag));
|
|
921
|
+
newVer = Math.max(previous + 1, newVer);
|
|
922
|
+
} else {
|
|
923
|
+
const key = this.nk(`tag_ver:${tag}`);
|
|
924
|
+
const current = await this._getTagVersion(tag);
|
|
925
|
+
newVer = Math.max(current + 1, Date.now());
|
|
926
|
+
await this.remoteStorage.set(key, String(newVer));
|
|
927
|
+
}
|
|
928
|
+
} catch {
|
|
929
|
+
const current = this.tagVersionCache.get(tag)?.version ?? 1;
|
|
930
|
+
newVer = current + 1;
|
|
931
|
+
}
|
|
932
|
+
} else {
|
|
933
|
+
const current = this.tagVersionCache.get(tag)?.version ?? 1;
|
|
934
|
+
newVer = current + 1;
|
|
935
|
+
}
|
|
936
|
+
this._setTagVersionCache(tag, newVer, Date.now() + this.tagVersionTtlMs);
|
|
937
|
+
const keys = this.tagIndex.get(tag);
|
|
938
|
+
if (keys) {
|
|
939
|
+
const keysArr = Array.from(keys);
|
|
940
|
+
for (const k of keysArr) {
|
|
941
|
+
this._deleteL1(k);
|
|
942
|
+
}
|
|
943
|
+
this.tagIndex.delete(tag);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
818
946
|
/**
|
|
819
947
|
* Invalidates all cached entries associated with a tag.
|
|
820
948
|
*/
|
|
@@ -841,38 +969,11 @@ var EdgeCacheService = class {
|
|
|
841
969
|
}
|
|
842
970
|
if (shouldCascade && !isPattern) matched.add(tag);
|
|
843
971
|
for (const t of matched) {
|
|
844
|
-
await this.
|
|
972
|
+
await this._invalidateConcreteTag(t);
|
|
845
973
|
}
|
|
846
974
|
return;
|
|
847
975
|
}
|
|
848
|
-
|
|
849
|
-
if (this.remoteStorage) {
|
|
850
|
-
try {
|
|
851
|
-
if (typeof this.remoteStorage.incrementTagVersion === "function") {
|
|
852
|
-
newVer = await this.remoteStorage.incrementTagVersion(this.nk(tag));
|
|
853
|
-
} else {
|
|
854
|
-
const key = this.nk(`tag_ver:${tag}`);
|
|
855
|
-
const current = await this._getTagVersion(tag);
|
|
856
|
-
newVer = Math.max(current + 1, Date.now());
|
|
857
|
-
await this.remoteStorage.set(key, String(newVer));
|
|
858
|
-
}
|
|
859
|
-
} catch {
|
|
860
|
-
const current = this.tagVersionCache.get(tag)?.version ?? 1;
|
|
861
|
-
newVer = current + 1;
|
|
862
|
-
}
|
|
863
|
-
} else {
|
|
864
|
-
const current = this.tagVersionCache.get(tag)?.version ?? 1;
|
|
865
|
-
newVer = current + 1;
|
|
866
|
-
}
|
|
867
|
-
this.tagVersionCache.set(tag, { version: newVer, expiresAt: Date.now() + 6e4 });
|
|
868
|
-
const keys = this.tagIndex.get(tag);
|
|
869
|
-
if (keys) {
|
|
870
|
-
const keysArr = Array.from(keys);
|
|
871
|
-
for (const k of keysArr) {
|
|
872
|
-
this._deleteL1(k);
|
|
873
|
-
}
|
|
874
|
-
this.tagIndex.delete(tag);
|
|
875
|
-
}
|
|
976
|
+
await this._invalidateConcreteTag(tag);
|
|
876
977
|
} catch (err) {
|
|
877
978
|
span.setStatus({ code: 2, message: err instanceof Error ? err.message : String(err) });
|
|
878
979
|
span.recordException?.(err);
|
|
@@ -887,6 +988,8 @@ var EdgeCacheService = class {
|
|
|
887
988
|
async clear() {
|
|
888
989
|
const span = this._startSpan("tricache.clear");
|
|
889
990
|
try {
|
|
991
|
+
const previousNamespace = await this._getTagVersion(NAMESPACE_TAG);
|
|
992
|
+
this.invalidateWork();
|
|
890
993
|
this.l1.clear();
|
|
891
994
|
this.currentBytes = 0;
|
|
892
995
|
this.tagIndex.clear();
|
|
@@ -895,8 +998,10 @@ var EdgeCacheService = class {
|
|
|
895
998
|
this.bloomFilter.reset();
|
|
896
999
|
}
|
|
897
1000
|
if (this.remoteStorage) {
|
|
898
|
-
await this.remoteStorage.clear?.(this.namespace
|
|
1001
|
+
await this.remoteStorage.clear?.(this.namespace ? this.namespace + ":" : void 0);
|
|
899
1002
|
}
|
|
1003
|
+
this._setTagVersionCache(NAMESPACE_TAG, previousNamespace, Date.now() + this.tagVersionTtlMs);
|
|
1004
|
+
await this._invalidateConcreteTag(NAMESPACE_TAG);
|
|
900
1005
|
} catch (err) {
|
|
901
1006
|
span.setStatus({ code: 2, message: err instanceof Error ? err.message : String(err) });
|
|
902
1007
|
span.recordException?.(err);
|
|
@@ -910,6 +1015,7 @@ var EdgeCacheService = class {
|
|
|
910
1015
|
*/
|
|
911
1016
|
async mget(keys, fetchFn, ttlSeconds) {
|
|
912
1017
|
const span = this._startSpan("tricache.mget");
|
|
1018
|
+
const epochs = new Map(keys.map((key) => [key, this.fence(this.nk(key))]));
|
|
913
1019
|
span.setAttribute("cache.batch.size", keys.length);
|
|
914
1020
|
try {
|
|
915
1021
|
const results = Array.from({ length: keys.length }, () => null);
|
|
@@ -931,10 +1037,10 @@ var EdgeCacheService = class {
|
|
|
931
1037
|
const isMap = fetchedMap instanceof Map;
|
|
932
1038
|
for (let j = 0; j < missKeys.length; j++) {
|
|
933
1039
|
const k = missKeys[j];
|
|
934
|
-
const fetchedVal = isMap ? fetchedMap.get(k) : fetchedMap[k];
|
|
1040
|
+
const fetchedVal = isMap ? fetchedMap.get(k) : Object.hasOwn(fetchedMap, k) ? fetchedMap[k] : void 0;
|
|
935
1041
|
if (fetchedVal !== void 0) {
|
|
936
1042
|
results[missIndices[j]] = fetchedVal;
|
|
937
|
-
await this.set(k, fetchedVal, ttlSeconds);
|
|
1043
|
+
if (this.fence(this.nk(k)) === epochs.get(k)) await this.set(k, fetchedVal, ttlSeconds);
|
|
938
1044
|
}
|
|
939
1045
|
}
|
|
940
1046
|
}
|
|
@@ -996,6 +1102,7 @@ var EdgeCacheService = class {
|
|
|
996
1102
|
* }
|
|
997
1103
|
*/
|
|
998
1104
|
async hydrate(source, options) {
|
|
1105
|
+
const epoch = this.globalEpoch;
|
|
999
1106
|
let rawStr = null;
|
|
1000
1107
|
if (source && typeof source === "object") {
|
|
1001
1108
|
if ("get" in source && typeof source.get === "function") {
|
|
@@ -1034,13 +1141,14 @@ var EdgeCacheService = class {
|
|
|
1034
1141
|
} catch {
|
|
1035
1142
|
return 0;
|
|
1036
1143
|
}
|
|
1037
|
-
if (!payload || !Array.isArray(payload.entries)) {
|
|
1144
|
+
if (!payload || payload.version !== 1 || !Array.isArray(payload.entries) || this.globalEpoch !== epoch) {
|
|
1038
1145
|
return 0;
|
|
1039
1146
|
}
|
|
1040
1147
|
const now = Date.now();
|
|
1041
1148
|
const maxAgeMs = options?.maxAgeMs ?? 72e5;
|
|
1042
1149
|
const tolerance = options?.clockSkewToleranceMs ?? 250;
|
|
1043
1150
|
const writtenAt = payload.writtenAt ?? 0;
|
|
1151
|
+
if (!Number.isFinite(writtenAt) || writtenAt < this.lastGlobalMutationAt) return 0;
|
|
1044
1152
|
if (writtenAt - now > tolerance) {
|
|
1045
1153
|
return 0;
|
|
1046
1154
|
}
|
|
@@ -1053,8 +1161,10 @@ var EdgeCacheService = class {
|
|
|
1053
1161
|
if (!item || typeof item.key !== "string") continue;
|
|
1054
1162
|
if (item.expiresAt <= now && item.staleUntil <= now) continue;
|
|
1055
1163
|
const nsKey = this.nk(item.key);
|
|
1164
|
+
if (this.l1.has(nsKey) || this.keyEpochs.has(nsKey) || !Number.isFinite(item.expiresAt) || !Number.isFinite(item.staleUntil)) continue;
|
|
1056
1165
|
const serialized = JSON.stringify(item.value);
|
|
1057
1166
|
const bytes = this._estimateBytes(nsKey, serialized);
|
|
1167
|
+
if (bytes > this.maxBytes || this.maxKeys === 0) continue;
|
|
1058
1168
|
this._deleteL1(nsKey);
|
|
1059
1169
|
this._evictIfNeeded(bytes);
|
|
1060
1170
|
const entry = {
|
|
@@ -1079,7 +1189,7 @@ var EdgeCacheService = class {
|
|
|
1079
1189
|
}
|
|
1080
1190
|
}
|
|
1081
1191
|
if (this.bloomFilter) {
|
|
1082
|
-
this.bloomFilter.add(
|
|
1192
|
+
this.bloomFilter.add(nsKey);
|
|
1083
1193
|
}
|
|
1084
1194
|
imported++;
|
|
1085
1195
|
}
|
|
@@ -1473,7 +1583,6 @@ function honoEdgeCache(options = {}) {
|
|
|
1473
1583
|
cache,
|
|
1474
1584
|
etag = true,
|
|
1475
1585
|
ttl = 300,
|
|
1476
|
-
swr,
|
|
1477
1586
|
tags,
|
|
1478
1587
|
skipCache,
|
|
1479
1588
|
keyGenerator,
|
|
@@ -1487,6 +1596,8 @@ function honoEdgeCache(options = {}) {
|
|
|
1487
1596
|
if (skipCache && skipCache(c)) {
|
|
1488
1597
|
return await next();
|
|
1489
1598
|
}
|
|
1599
|
+
const credentials = ["authorization", "cookie", "x-api-key", "x-auth-token"].filter((name) => c.req.header?.(name));
|
|
1600
|
+
if (c.req.header?.("range") || credentials.length > 0 && (!options.cacheAuthenticated || !keyGenerator && !credentials.every((name) => headerWhitelist?.some((header) => header.toLowerCase() === name)))) return await next();
|
|
1490
1601
|
const cc = c.req.header?.("cache-control") || c.req.header?.("Cache-Control");
|
|
1491
1602
|
if (typeof cc === "string") {
|
|
1492
1603
|
const lower = cc.toLowerCase();
|
|
@@ -1497,7 +1608,12 @@ function honoEdgeCache(options = {}) {
|
|
|
1497
1608
|
if (!cache) {
|
|
1498
1609
|
return await next();
|
|
1499
1610
|
}
|
|
1500
|
-
|
|
1611
|
+
let key = buildEdgeDeterministicKey(c, { keyGenerator, headerWhitelist });
|
|
1612
|
+
if (credentials.length) {
|
|
1613
|
+
if (!globalThis.crypto?.subtle) return await next();
|
|
1614
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(key));
|
|
1615
|
+
key = `edge:http:identity:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
1616
|
+
}
|
|
1501
1617
|
const ifNoneMatch = c.req.header?.("if-none-match") || c.req.header?.("If-None-Match");
|
|
1502
1618
|
const resolvedTags = typeof tags === "function" ? tags(c) : tags;
|
|
1503
1619
|
let ranNext = false;
|
|
@@ -1520,6 +1636,10 @@ function honoEdgeCache(options = {}) {
|
|
|
1520
1636
|
});
|
|
1521
1637
|
}
|
|
1522
1638
|
const cc2 = res.headers?.get?.("cache-control");
|
|
1639
|
+
const vary = String(res.headers?.get?.("vary") ?? "").split(",").map((name) => name.trim().toLowerCase()).filter(Boolean);
|
|
1640
|
+
if (res.headers?.get?.("set-cookie") || vary.includes("*") || !keyGenerator && vary.some((name) => !headerWhitelist?.some((header) => header.toLowerCase() === name))) {
|
|
1641
|
+
throw new NonCacheableEdgeResponseError({ body: "", contentType, status: 0 });
|
|
1642
|
+
}
|
|
1523
1643
|
if (cc2) {
|
|
1524
1644
|
const lowerCc = cc2.toLowerCase();
|
|
1525
1645
|
if (lowerCc.includes("no-store") || lowerCc.includes("no-cache") || lowerCc.includes("private")) {
|
|
@@ -1561,9 +1681,9 @@ function honoEdgeCache(options = {}) {
|
|
|
1561
1681
|
},
|
|
1562
1682
|
ttl,
|
|
1563
1683
|
{
|
|
1564
|
-
swr,
|
|
1684
|
+
swr: 0,
|
|
1565
1685
|
tags: resolvedTags,
|
|
1566
|
-
ctx: c
|
|
1686
|
+
ctx: readExecutionContext(c)
|
|
1567
1687
|
}
|
|
1568
1688
|
);
|
|
1569
1689
|
if (!cached) {
|
|
@@ -1590,6 +1710,13 @@ function honoEdgeCache(options = {}) {
|
|
|
1590
1710
|
}
|
|
1591
1711
|
};
|
|
1592
1712
|
}
|
|
1713
|
+
function readExecutionContext(c) {
|
|
1714
|
+
try {
|
|
1715
|
+
return c.executionCtx;
|
|
1716
|
+
} catch {
|
|
1717
|
+
return void 0;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1593
1720
|
function applyEdgeResponse(c, body, status, headers) {
|
|
1594
1721
|
const response = c.body(body, status, headers);
|
|
1595
1722
|
c.res = response;
|