tricache 0.9.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 +7 -3
- package/dist/{cache-service-KI5ACF3F.js → cache-service-26GCO3UU.js} +3 -3
- package/dist/{cache-service-DVvroyqA.d.ts → cache-service-pJ-nFcVj.d.ts} +29 -12
- package/dist/{chunk-XZL45ABR.js → chunk-2AJKEQMZ.js} +54 -1
- package/dist/{chunk-PL5J3ZNT.js → chunk-7SZSQS55.js} +201 -34
- package/dist/{chunk-LJ5QJB5O.js → chunk-UBWLPKTI.js} +127 -11
- package/dist/cli.cjs +376 -50
- package/dist/cli.js +4 -4
- package/dist/dashboard/index.d.ts +2 -2
- package/dist/drizzle/index.cjs +384 -51
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +64 -8
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +37 -9
- package/dist/hono/index.cjs +384 -51
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +1 -1
- package/dist/{hono-VA9A1m0I.d.ts → hono-DuNvciyq.d.ts} +4 -4
- package/dist/http/index.cjs +384 -51
- package/dist/http/index.d.ts +3 -3
- package/dist/http/index.js +8 -8
- package/dist/index.cjs +385 -49
- package/dist/index.d.ts +35 -6
- package/dist/index.js +16 -6
- package/dist/nestjs/index.cjs +375 -49
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +4 -4
- package/dist/next/index.cjs +375 -49
- 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-B_QkVwJ7.d.ts → types-5HXqBfAf.d.ts} +51 -7
- package/package.json +7 -4
- package/src/cache-service.ts +238 -33
- package/src/cli.ts +1 -1
- package/src/compression.ts +193 -15
- package/src/cross-region.ts +1 -1
- package/src/edge/cache.ts +38 -11
- package/src/env.d.ts +13 -0
- package/src/index.ts +9 -1
- package/src/serialize-worker.ts +6 -2
- package/src/types.ts +43 -5
- package/src/utils/tag-matcher.ts +90 -0
- /package/dist/{chunk-QNU7B43J.js → chunk-VXFTFZ5N.js} +0 -0
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);
|
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
|
@@ -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-
|
|
14
|
+
} from "../chunk-2AJKEQMZ.js";
|
|
12
15
|
import {
|
|
13
16
|
buildEdgeDeterministicKey,
|
|
14
17
|
computeEdgeETag,
|
|
@@ -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);
|