tricache 0.9.0 → 1.0.1

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.
Files changed (53) hide show
  1. package/README.md +7 -3
  2. package/dist/{cache-service-DVvroyqA.d.ts → cache-service-CREOp7MM.d.ts} +57 -12
  3. package/dist/{cache-service-KI5ACF3F.js → cache-service-MG7PN6MX.js} +3 -3
  4. package/dist/{chunk-XZL45ABR.js → chunk-2AJKEQMZ.js} +54 -1
  5. package/dist/{chunk-QNU7B43J.js → chunk-3I5L7K6I.js} +17 -0
  6. package/dist/{chunk-PL5J3ZNT.js → chunk-JYQFQJNJ.js} +682 -277
  7. package/dist/{chunk-LJ5QJB5O.js → chunk-UBWLPKTI.js} +127 -11
  8. package/dist/cli.cjs +857 -293
  9. package/dist/cli.js +4 -4
  10. package/dist/dashboard/index.d.ts +2 -2
  11. package/dist/drizzle/index.cjs +865 -294
  12. package/dist/drizzle/index.d.ts +2 -2
  13. package/dist/drizzle/index.js +1 -1
  14. package/dist/edge/index.cjs +115 -36
  15. package/dist/edge/index.d.ts +3 -3
  16. package/dist/edge/index.js +88 -37
  17. package/dist/hono/index.cjs +865 -294
  18. package/dist/hono/index.d.ts +2 -2
  19. package/dist/hono/index.js +1 -1
  20. package/dist/{hono-VA9A1m0I.d.ts → hono-DSV2ve66.d.ts} +11 -4
  21. package/dist/http/index.cjs +917 -315
  22. package/dist/http/index.d.ts +3 -3
  23. package/dist/http/index.js +60 -29
  24. package/dist/index.cjs +885 -294
  25. package/dist/index.d.ts +37 -7
  26. package/dist/index.js +16 -6
  27. package/dist/nestjs/index.cjs +856 -292
  28. package/dist/nestjs/index.d.ts +2 -2
  29. package/dist/nestjs/index.js +4 -4
  30. package/dist/next/index.cjs +858 -300
  31. package/dist/next/index.d.ts +2 -2
  32. package/dist/next/index.js +5 -11
  33. package/dist/prisma/index.d.ts +2 -2
  34. package/dist/serialize-worker.cjs +127 -9
  35. package/dist/serialize-worker.js +8 -4
  36. package/dist/{types-B_QkVwJ7.d.ts → types-Dyip5wAl.d.ts} +53 -7
  37. package/package.json +7 -4
  38. package/src/adapters/node-redis.ts +19 -0
  39. package/src/cache-service.ts +781 -297
  40. package/src/cli.ts +1 -1
  41. package/src/compression.ts +193 -15
  42. package/src/cross-region.ts +1 -1
  43. package/src/edge/cache.ts +94 -42
  44. package/src/env.d.ts +13 -0
  45. package/src/http/express.ts +55 -16
  46. package/src/http/fastify.ts +3 -7
  47. package/src/index.ts +9 -1
  48. package/src/next/cache-handler.ts +1 -4
  49. package/src/next/isr-handler.ts +1 -4
  50. package/src/serialize-worker.ts +6 -2
  51. package/src/smart-memory-cache.ts +3 -2
  52. package/src/types.ts +45 -5
  53. package/src/utils/tag-matcher.ts +90 -0
@@ -1,5 +1,5 @@
1
- import { C as CacheService } from '../cache-service-DVvroyqA.js';
2
- import { W as WrapOptions } from '../types-B_QkVwJ7.js';
1
+ import { C as CacheService } from '../cache-service-CREOp7MM.js';
2
+ import { W as WrapOptions } from '../types-Dyip5wAl.js';
3
3
  import 'crypto';
4
4
 
5
5
  /**
@@ -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-KI5ACF3F.js");
12
+ const { CacheService } = await import("../cache-service-MG7PN6MX.js");
13
13
  activeCache = CacheService.create();
14
14
  }
15
15
  let cacheKey = key;
@@ -406,8 +406,39 @@ 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
- var EdgeCacheService = class {
441
+ var EdgeCacheService = class _EdgeCacheService {
411
442
  maxKeys;
412
443
  maxBytes;
413
444
  defaultTtl;
@@ -424,6 +455,7 @@ var EdgeCacheService = class {
424
455
  // Tag indexing for edge
425
456
  tagIndex = /* @__PURE__ */ new Map();
426
457
  // Tag version in-isolate cache with 800ms micro-TTL (prevents HTTP fetch amplification on L1 hits)
458
+ static MAX_TAG_VERSION_CACHE = 1e4;
427
459
  tagVersionCache = /* @__PURE__ */ new Map();
428
460
  tagVersionTtlMs = 800;
429
461
  constructor(options) {
@@ -506,6 +538,21 @@ var EdgeCacheService = class {
506
538
  }
507
539
  };
508
540
  }
541
+ _setTagVersionCache(tag, version, expiresAt) {
542
+ if (this.tagVersionCache.size >= _EdgeCacheService.MAX_TAG_VERSION_CACHE && !this.tagVersionCache.has(tag)) {
543
+ const now = Date.now();
544
+ for (const [k, v] of this.tagVersionCache) {
545
+ if (v.expiresAt <= now) {
546
+ this.tagVersionCache.delete(k);
547
+ }
548
+ }
549
+ if (this.tagVersionCache.size >= _EdgeCacheService.MAX_TAG_VERSION_CACHE) {
550
+ const oldestKey = this.tagVersionCache.keys().next().value;
551
+ if (oldestKey !== void 0) this.tagVersionCache.delete(oldestKey);
552
+ }
553
+ }
554
+ this.tagVersionCache.set(tag, { version, expiresAt });
555
+ }
509
556
  async _getTagVersion(tag) {
510
557
  const cached = this.tagVersionCache.get(tag);
511
558
  const now = Date.now();
@@ -527,7 +574,7 @@ var EdgeCacheService = class {
527
574
  } else {
528
575
  version = cached?.version ?? 1;
529
576
  }
530
- this.tagVersionCache.set(tag, { version, expiresAt: now + this.tagVersionTtlMs });
577
+ this._setTagVersionCache(tag, version, now + this.tagVersionTtlMs);
531
578
  return version;
532
579
  }
533
580
  async _batchGetTagVersions(tags) {
@@ -551,7 +598,7 @@ var EdgeCacheService = class {
551
598
  const t = missingTags[i];
552
599
  const v = remoteVersions[this.nk(t)] ?? remoteVersions[t] ?? 1;
553
600
  result[t] = v;
554
- this.tagVersionCache.set(t, { version: v, expiresAt: now + this.tagVersionTtlMs });
601
+ this._setTagVersionCache(t, v, now + this.tagVersionTtlMs);
555
602
  }
556
603
  } else {
557
604
  await Promise.all(missingTags.map(async (t) => {
@@ -716,11 +763,12 @@ var EdgeCacheService = class {
716
763
  const nsKey = this.nk(key);
717
764
  const resolvedTtl = ttlSeconds ?? this.defaultTtl;
718
765
  const now = Date.now();
719
- const swrSeconds = options?.swr ?? 0;
766
+ const optObj = Array.isArray(options) ? { tags: options } : options;
767
+ const swrSeconds = optObj?.swr ?? 0;
720
768
  try {
721
769
  let activeTagVersions;
722
- if (options?.tags?.length) {
723
- activeTagVersions = await this._batchGetTagVersions(options.tags);
770
+ if (optObj?.tags?.length) {
771
+ activeTagVersions = await this._batchGetTagVersions(optObj.tags);
724
772
  }
725
773
  const serialized = JSON.stringify(value);
726
774
  const bytes = this._estimateBytes(nsKey, serialized);
@@ -732,13 +780,13 @@ var EdgeCacheService = class {
732
780
  bytes,
733
781
  expiresAt: now + resolvedTtl * 1e3,
734
782
  staleUntil: now + (resolvedTtl + swrSeconds) * 1e3,
735
- tags: options?.tags,
783
+ tags: optObj?.tags,
736
784
  tagVersions: activeTagVersions
737
785
  };
738
786
  this.l1.set(nsKey, entry);
739
787
  this.currentBytes += bytes;
740
- if (options?.tags) {
741
- for (const tag of options.tags) {
788
+ if (optObj?.tags) {
789
+ for (const tag of optObj.tags) {
742
790
  let s = this.tagIndex.get(tag);
743
791
  if (!s) {
744
792
  s = /* @__PURE__ */ new Set();
@@ -783,41 +831,71 @@ var EdgeCacheService = class {
783
831
  span.end();
784
832
  }
785
833
  }
834
+ /**
835
+ * Executes invalidation for a single already-resolved concrete tag without
836
+ * re-entering wildcard/cascade resolution.
837
+ */
838
+ async _invalidateConcreteTag(tag) {
839
+ let newVer = 1;
840
+ if (this.remoteStorage) {
841
+ try {
842
+ if (typeof this.remoteStorage.incrementTagVersion === "function") {
843
+ newVer = await this.remoteStorage.incrementTagVersion(this.nk(tag));
844
+ } else {
845
+ const key = this.nk(`tag_ver:${tag}`);
846
+ const current = await this._getTagVersion(tag);
847
+ newVer = Math.max(current + 1, Date.now());
848
+ await this.remoteStorage.set(key, String(newVer));
849
+ }
850
+ } catch {
851
+ const current = this.tagVersionCache.get(tag)?.version ?? 1;
852
+ newVer = current + 1;
853
+ }
854
+ } else {
855
+ const current = this.tagVersionCache.get(tag)?.version ?? 1;
856
+ newVer = current + 1;
857
+ }
858
+ this._setTagVersionCache(tag, newVer, Date.now() + 6e4);
859
+ const keys = this.tagIndex.get(tag);
860
+ if (keys) {
861
+ const keysArr = Array.from(keys);
862
+ for (const k of keysArr) {
863
+ this._deleteL1(k);
864
+ }
865
+ this.tagIndex.delete(tag);
866
+ }
867
+ }
786
868
  /**
787
869
  * Invalidates all cached entries associated with a tag.
788
870
  */
789
- async invalidateTag(tag) {
871
+ async invalidateTag(tag, opts) {
790
872
  const span = this._startSpan("tricache.invalidate_tag");
791
873
  span.setAttribute("cache.tag", tag);
874
+ if (opts?.cascade) span.setAttribute("cache.cascade", true);
792
875
  try {
793
- let newVer = 1;
794
- if (this.remoteStorage) {
795
- try {
796
- if (typeof this.remoteStorage.incrementTagVersion === "function") {
797
- newVer = await this.remoteStorage.incrementTagVersion(this.nk(tag));
798
- } else {
799
- const key = this.nk(`tag_ver:${tag}`);
800
- const current = await this._getTagVersion(tag);
801
- newVer = Math.max(current + 1, Date.now());
802
- await this.remoteStorage.set(key, String(newVer));
803
- }
804
- } catch {
805
- const current = this.tagVersionCache.get(tag)?.version ?? 1;
806
- newVer = current + 1;
876
+ const isPattern = isWildcardTag(tag);
877
+ const shouldCascade = Boolean(opts?.cascade);
878
+ if (isPattern || shouldCascade) {
879
+ const matched = /* @__PURE__ */ new Set();
880
+ const tagMatches = (t) => {
881
+ if (t === tag) return true;
882
+ if (isPattern && matchesTagPattern(tag, t)) return true;
883
+ if (shouldCascade && isChildTag(tag, t, ":")) return true;
884
+ return false;
885
+ };
886
+ for (const t of this.tagIndex.keys()) {
887
+ if (tagMatches(t)) matched.add(t);
807
888
  }
808
- } else {
809
- const current = this.tagVersionCache.get(tag)?.version ?? 1;
810
- newVer = current + 1;
811
- }
812
- this.tagVersionCache.set(tag, { version: newVer, expiresAt: Date.now() + 6e4 });
813
- const keys = this.tagIndex.get(tag);
814
- if (keys) {
815
- const keysArr = Array.from(keys);
816
- for (const k of keysArr) {
817
- this._deleteL1(k);
889
+ for (const t of this.tagVersionCache.keys()) {
890
+ if (tagMatches(t)) matched.add(t);
818
891
  }
819
- this.tagIndex.delete(tag);
892
+ if (shouldCascade && !isPattern) matched.add(tag);
893
+ for (const t of matched) {
894
+ await this._invalidateConcreteTag(t);
895
+ }
896
+ return;
820
897
  }
898
+ await this._invalidateConcreteTag(tag);
821
899
  } catch (err) {
822
900
  span.setStatus({ code: 2, message: err instanceof Error ? err.message : String(err) });
823
901
  span.recordException?.(err);
@@ -873,9 +951,10 @@ var EdgeCacheService = class {
873
951
  span.setAttribute("cache.misses", missKeys.length);
874
952
  if (missKeys.length > 0 && fetchFn) {
875
953
  const fetchedMap = await fetchFn(missKeys);
954
+ const isMap = fetchedMap instanceof Map;
876
955
  for (let j = 0; j < missKeys.length; j++) {
877
956
  const k = missKeys[j];
878
- const fetchedVal = fetchedMap[k];
957
+ const fetchedVal = isMap ? fetchedMap.get(k) : fetchedMap[k];
879
958
  if (fetchedVal !== void 0) {
880
959
  results[missIndices[j]] = fetchedVal;
881
960
  await this.set(k, fetchedVal, ttlSeconds);
@@ -1,7 +1,7 @@
1
- import { I as IEdgeRemoteStorage, U as UpstashRedisOptions, a as CloudflareKVNamespace, d as CloudflareDOStorage } from '../hono-VA9A1m0I.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-VA9A1m0I.js';
1
+ import { I as IEdgeRemoteStorage, U as UpstashRedisOptions, a as CloudflareKVNamespace, d as CloudflareDOStorage } from '../hono-DSV2ve66.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-DSV2ve66.js';
3
3
  export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from '../murmur3-CMGw9PbV.js';
4
- import '../types-B_QkVwJ7.js';
4
+ import '../types-Dyip5wAl.js';
5
5
  import 'crypto';
6
6
 
7
7
  type WebCryptoMode = 'aes-256-gcm' | 'aes-128-gcm';
@@ -5,10 +5,13 @@ import {
5
5
  import {
6
6
  WasmBloomFilter,
7
7
  base64ToUint8Array,
8
+ isChildTag,
9
+ isWildcardTag,
10
+ matchesTagPattern,
8
11
  uint8ArrayToBase64,
9
12
  uint8ArrayToUtf8,
10
13
  utf8ToUint8Array
11
- } from "../chunk-XZL45ABR.js";
14
+ } from "../chunk-2AJKEQMZ.js";
12
15
  import {
13
16
  buildEdgeDeterministicKey,
14
17
  computeEdgeETag,
@@ -149,7 +152,7 @@ var WebCryptoEncryption = class {
149
152
  };
150
153
 
151
154
  // src/edge/cache.ts
152
- var EdgeCacheService = class {
155
+ var EdgeCacheService = class _EdgeCacheService {
153
156
  maxKeys;
154
157
  maxBytes;
155
158
  defaultTtl;
@@ -166,6 +169,7 @@ var EdgeCacheService = class {
166
169
  // Tag indexing for edge
167
170
  tagIndex = /* @__PURE__ */ new Map();
168
171
  // Tag version in-isolate cache with 800ms micro-TTL (prevents HTTP fetch amplification on L1 hits)
172
+ static MAX_TAG_VERSION_CACHE = 1e4;
169
173
  tagVersionCache = /* @__PURE__ */ new Map();
170
174
  tagVersionTtlMs = 800;
171
175
  constructor(options) {
@@ -248,6 +252,21 @@ var EdgeCacheService = class {
248
252
  }
249
253
  };
250
254
  }
255
+ _setTagVersionCache(tag, version, expiresAt) {
256
+ if (this.tagVersionCache.size >= _EdgeCacheService.MAX_TAG_VERSION_CACHE && !this.tagVersionCache.has(tag)) {
257
+ const now = Date.now();
258
+ for (const [k, v] of this.tagVersionCache) {
259
+ if (v.expiresAt <= now) {
260
+ this.tagVersionCache.delete(k);
261
+ }
262
+ }
263
+ if (this.tagVersionCache.size >= _EdgeCacheService.MAX_TAG_VERSION_CACHE) {
264
+ const oldestKey = this.tagVersionCache.keys().next().value;
265
+ if (oldestKey !== void 0) this.tagVersionCache.delete(oldestKey);
266
+ }
267
+ }
268
+ this.tagVersionCache.set(tag, { version, expiresAt });
269
+ }
251
270
  async _getTagVersion(tag) {
252
271
  const cached = this.tagVersionCache.get(tag);
253
272
  const now = Date.now();
@@ -269,7 +288,7 @@ var EdgeCacheService = class {
269
288
  } else {
270
289
  version = cached?.version ?? 1;
271
290
  }
272
- this.tagVersionCache.set(tag, { version, expiresAt: now + this.tagVersionTtlMs });
291
+ this._setTagVersionCache(tag, version, now + this.tagVersionTtlMs);
273
292
  return version;
274
293
  }
275
294
  async _batchGetTagVersions(tags) {
@@ -293,7 +312,7 @@ var EdgeCacheService = class {
293
312
  const t = missingTags[i];
294
313
  const v = remoteVersions[this.nk(t)] ?? remoteVersions[t] ?? 1;
295
314
  result[t] = v;
296
- this.tagVersionCache.set(t, { version: v, expiresAt: now + this.tagVersionTtlMs });
315
+ this._setTagVersionCache(t, v, now + this.tagVersionTtlMs);
297
316
  }
298
317
  } else {
299
318
  await Promise.all(missingTags.map(async (t) => {
@@ -458,11 +477,12 @@ var EdgeCacheService = class {
458
477
  const nsKey = this.nk(key);
459
478
  const resolvedTtl = ttlSeconds ?? this.defaultTtl;
460
479
  const now = Date.now();
461
- const swrSeconds = options?.swr ?? 0;
480
+ const optObj = Array.isArray(options) ? { tags: options } : options;
481
+ const swrSeconds = optObj?.swr ?? 0;
462
482
  try {
463
483
  let activeTagVersions;
464
- if (options?.tags?.length) {
465
- activeTagVersions = await this._batchGetTagVersions(options.tags);
484
+ if (optObj?.tags?.length) {
485
+ activeTagVersions = await this._batchGetTagVersions(optObj.tags);
466
486
  }
467
487
  const serialized = JSON.stringify(value);
468
488
  const bytes = this._estimateBytes(nsKey, serialized);
@@ -474,13 +494,13 @@ var EdgeCacheService = class {
474
494
  bytes,
475
495
  expiresAt: now + resolvedTtl * 1e3,
476
496
  staleUntil: now + (resolvedTtl + swrSeconds) * 1e3,
477
- tags: options?.tags,
497
+ tags: optObj?.tags,
478
498
  tagVersions: activeTagVersions
479
499
  };
480
500
  this.l1.set(nsKey, entry);
481
501
  this.currentBytes += bytes;
482
- if (options?.tags) {
483
- for (const tag of options.tags) {
502
+ if (optObj?.tags) {
503
+ for (const tag of optObj.tags) {
484
504
  let s = this.tagIndex.get(tag);
485
505
  if (!s) {
486
506
  s = /* @__PURE__ */ new Set();
@@ -525,41 +545,71 @@ var EdgeCacheService = class {
525
545
  span.end();
526
546
  }
527
547
  }
548
+ /**
549
+ * Executes invalidation for a single already-resolved concrete tag without
550
+ * re-entering wildcard/cascade resolution.
551
+ */
552
+ async _invalidateConcreteTag(tag) {
553
+ let newVer = 1;
554
+ if (this.remoteStorage) {
555
+ try {
556
+ if (typeof this.remoteStorage.incrementTagVersion === "function") {
557
+ newVer = await this.remoteStorage.incrementTagVersion(this.nk(tag));
558
+ } else {
559
+ const key = this.nk(`tag_ver:${tag}`);
560
+ const current = await this._getTagVersion(tag);
561
+ newVer = Math.max(current + 1, Date.now());
562
+ await this.remoteStorage.set(key, String(newVer));
563
+ }
564
+ } catch {
565
+ const current = this.tagVersionCache.get(tag)?.version ?? 1;
566
+ newVer = current + 1;
567
+ }
568
+ } else {
569
+ const current = this.tagVersionCache.get(tag)?.version ?? 1;
570
+ newVer = current + 1;
571
+ }
572
+ this._setTagVersionCache(tag, newVer, Date.now() + 6e4);
573
+ const keys = this.tagIndex.get(tag);
574
+ if (keys) {
575
+ const keysArr = Array.from(keys);
576
+ for (const k of keysArr) {
577
+ this._deleteL1(k);
578
+ }
579
+ this.tagIndex.delete(tag);
580
+ }
581
+ }
528
582
  /**
529
583
  * Invalidates all cached entries associated with a tag.
530
584
  */
531
- async invalidateTag(tag) {
585
+ async invalidateTag(tag, opts) {
532
586
  const span = this._startSpan("tricache.invalidate_tag");
533
587
  span.setAttribute("cache.tag", tag);
588
+ if (opts?.cascade) span.setAttribute("cache.cascade", true);
534
589
  try {
535
- let newVer = 1;
536
- if (this.remoteStorage) {
537
- try {
538
- if (typeof this.remoteStorage.incrementTagVersion === "function") {
539
- newVer = await this.remoteStorage.incrementTagVersion(this.nk(tag));
540
- } else {
541
- const key = this.nk(`tag_ver:${tag}`);
542
- const current = await this._getTagVersion(tag);
543
- newVer = Math.max(current + 1, Date.now());
544
- await this.remoteStorage.set(key, String(newVer));
545
- }
546
- } catch {
547
- const current = this.tagVersionCache.get(tag)?.version ?? 1;
548
- newVer = current + 1;
590
+ const isPattern = isWildcardTag(tag);
591
+ const shouldCascade = Boolean(opts?.cascade);
592
+ if (isPattern || shouldCascade) {
593
+ const matched = /* @__PURE__ */ new Set();
594
+ const tagMatches = (t) => {
595
+ if (t === tag) return true;
596
+ if (isPattern && matchesTagPattern(tag, t)) return true;
597
+ if (shouldCascade && isChildTag(tag, t, ":")) return true;
598
+ return false;
599
+ };
600
+ for (const t of this.tagIndex.keys()) {
601
+ if (tagMatches(t)) matched.add(t);
549
602
  }
550
- } else {
551
- const current = this.tagVersionCache.get(tag)?.version ?? 1;
552
- newVer = current + 1;
553
- }
554
- this.tagVersionCache.set(tag, { version: newVer, expiresAt: Date.now() + 6e4 });
555
- const keys = this.tagIndex.get(tag);
556
- if (keys) {
557
- const keysArr = Array.from(keys);
558
- for (const k of keysArr) {
559
- this._deleteL1(k);
603
+ for (const t of this.tagVersionCache.keys()) {
604
+ if (tagMatches(t)) matched.add(t);
605
+ }
606
+ if (shouldCascade && !isPattern) matched.add(tag);
607
+ for (const t of matched) {
608
+ await this._invalidateConcreteTag(t);
560
609
  }
561
- this.tagIndex.delete(tag);
610
+ return;
562
611
  }
612
+ await this._invalidateConcreteTag(tag);
563
613
  } catch (err) {
564
614
  span.setStatus({ code: 2, message: err instanceof Error ? err.message : String(err) });
565
615
  span.recordException?.(err);
@@ -615,9 +665,10 @@ var EdgeCacheService = class {
615
665
  span.setAttribute("cache.misses", missKeys.length);
616
666
  if (missKeys.length > 0 && fetchFn) {
617
667
  const fetchedMap = await fetchFn(missKeys);
668
+ const isMap = fetchedMap instanceof Map;
618
669
  for (let j = 0; j < missKeys.length; j++) {
619
670
  const k = missKeys[j];
620
- const fetchedVal = fetchedMap[k];
671
+ const fetchedVal = isMap ? fetchedMap.get(k) : fetchedMap[k];
621
672
  if (fetchedVal !== void 0) {
622
673
  results[missIndices[j]] = fetchedVal;
623
674
  await this.set(k, fetchedVal, ttlSeconds);