tricache 1.0.1 → 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-CREOp7MM.d.ts → cache-service-B108FzER.d.ts} +36 -4
- package/dist/cache-service-CWI4jkS7.d.cts +963 -0
- package/dist/{cache-service-MG7PN6MX.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-3I5L7K6I.js → chunk-VNRDL5RA.js} +102 -140
- package/dist/{chunk-JYQFQJNJ.js → chunk-WYF7NOAT.js} +1443 -609
- package/dist/cli.cjs +1367 -625
- 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 +1370 -624
- 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 +227 -123
- package/dist/edge/index.d.cts +127 -0
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +201 -117
- package/dist/hono/index.cjs +1418 -644
- 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-DSV2ve66.d.ts → hono-3rDMYVtY.d.ts} +16 -3
- package/dist/hono-C886ok3X.d.cts +391 -0
- package/dist/http/index.cjs +1514 -679
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +92 -43
- package/dist/index.cjs +1671 -790
- package/dist/index.d.cts +1006 -0
- package/dist/index.d.ts +39 -8
- package/dist/index.js +8 -8
- package/dist/murmur3-CMGw9PbV.d.cts +98 -0
- package/dist/nestjs/index.cjs +1454 -649
- 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 +1512 -718
- package/dist/next/index.d.cts +232 -0
- package/dist/next/index.d.ts +33 -11
- package/dist/next/index.js +172 -99
- 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-Dyip5wAl.d.ts → types-BA4pz1A0.d.cts} +24 -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 +106 -27
- package/src/cache-service.ts +802 -502
- 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 +145 -97
- 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 +62 -17
- package/src/http/fastify.ts +35 -21
- 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 +131 -53
- package/src/next/index.ts +1 -0
- package/src/next/types.ts +21 -0
- package/src/prisma/index.ts +12 -1
- package/src/smart-memory-cache.ts +63 -26
- package/src/types.ts +25 -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/prisma/index.cjs
CHANGED
|
@@ -57,8 +57,14 @@ var MUTATION_OPERATIONS = /* @__PURE__ */ new Set([
|
|
|
57
57
|
"deleteMany"
|
|
58
58
|
]);
|
|
59
59
|
function deterministicStringify(val) {
|
|
60
|
+
if (val instanceof Date) return `date:${JSON.stringify(val.toISOString())}`;
|
|
61
|
+
if (typeof val === "bigint") return `bigint:${val}`;
|
|
62
|
+
if (val instanceof Uint8Array) return `binary:${Buffer.from(val.buffer, val.byteOffset, val.byteLength).toString("base64")}`;
|
|
63
|
+
if (val && typeof val === "object" && typeof val.toJSON === "function") {
|
|
64
|
+
return deterministicStringify(val.toJSON());
|
|
65
|
+
}
|
|
60
66
|
if (val === null || typeof val !== "object") {
|
|
61
|
-
return JSON.stringify(val);
|
|
67
|
+
return JSON.stringify(val) ?? "undefined";
|
|
62
68
|
}
|
|
63
69
|
if (Array.isArray(val)) {
|
|
64
70
|
return `[${val.map(deterministicStringify).join(",")}]`;
|
|
@@ -89,6 +95,10 @@ function withTriCache(options) {
|
|
|
89
95
|
if (READ_OPERATIONS.has(operation)) {
|
|
90
96
|
const queryArgs = args ?? {};
|
|
91
97
|
const cacheConfig = queryArgs.cache;
|
|
98
|
+
if (cacheConfig === false) {
|
|
99
|
+
const { cache: _c, ...cleanArgs } = queryArgs;
|
|
100
|
+
return query(cleanArgs);
|
|
101
|
+
}
|
|
92
102
|
if (cacheConfig !== void 0 || autoCache) {
|
|
93
103
|
const opts = typeof cacheConfig === "object" && cacheConfig !== null ? cacheConfig : {};
|
|
94
104
|
const { cache: _c, ...cleanArgs } = queryArgs;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { C as CacheService } from '../cache-service-CWI4jkS7.cjs';
|
|
2
|
+
import { W as WrapOptions } from '../types-BA4pz1A0.cjs';
|
|
3
|
+
import 'crypto';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* tricache/prisma — First-class Prisma Client extension for TriCache.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { PrismaClient } from '@prisma/client';
|
|
10
|
+
* import { withTriCache } from 'tricache/prisma';
|
|
11
|
+
*
|
|
12
|
+
* const prisma = new PrismaClient().$extends(
|
|
13
|
+
* withTriCache({
|
|
14
|
+
* cache,
|
|
15
|
+
* defaultTtl: 300,
|
|
16
|
+
* autoInvalidate: true, // Invalidate model tags on create/update/delete
|
|
17
|
+
* })
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* // Query with cache options:
|
|
21
|
+
* const users = await prisma.user.findMany({
|
|
22
|
+
* where: { active: true },
|
|
23
|
+
* cache: { ttl: 60, tags: ['users'], swr: 30 },
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface PrismaCacheQueryOptions extends WrapOptions {
|
|
28
|
+
/** Explicit cache key. Defaults to SHA-256 hash of (model + operation + args). */
|
|
29
|
+
key?: string;
|
|
30
|
+
/** Explicit tags for invalidation. Automatically includes `[model.toLowerCase()]`. */
|
|
31
|
+
tags?: string[];
|
|
32
|
+
}
|
|
33
|
+
interface PrismaTriCacheOptions {
|
|
34
|
+
/** TriCache instance to use for caching. */
|
|
35
|
+
cache: CacheService;
|
|
36
|
+
/** Default TTL in seconds for cached queries (default: 300 s). */
|
|
37
|
+
defaultTtl?: number;
|
|
38
|
+
/** Whether to automatically invalidate model tags on write operations (default: true). */
|
|
39
|
+
autoInvalidate?: boolean;
|
|
40
|
+
/** Automatically cache all read queries even if `cache` options are not provided (default: false). */
|
|
41
|
+
autoCache?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** Generate a deterministic SHA-256 hash key for a Prisma query. */
|
|
44
|
+
declare function generatePrismaCacheKey(model: string, operation: string, args: unknown): string;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Prisma Client Extension for TriCache.
|
|
47
|
+
*/
|
|
48
|
+
declare function withTriCache(options: PrismaTriCacheOptions): {
|
|
49
|
+
name: string;
|
|
50
|
+
query: {
|
|
51
|
+
$allModels: {
|
|
52
|
+
$allOperations({ model, operation, args, query }: {
|
|
53
|
+
model: string;
|
|
54
|
+
operation: string;
|
|
55
|
+
args: Record<string, unknown> | undefined;
|
|
56
|
+
query: (args: unknown) => Promise<unknown>;
|
|
57
|
+
}): Promise<unknown>;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { type PrismaCacheQueryOptions, type PrismaTriCacheOptions, generatePrismaCacheKey, withTriCache };
|
package/dist/prisma/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-B108FzER.js';
|
|
2
|
+
import { W as WrapOptions } from '../types-BA4pz1A0.js';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/prisma/index.js
CHANGED
|
@@ -22,8 +22,14 @@ var MUTATION_OPERATIONS = /* @__PURE__ */ new Set([
|
|
|
22
22
|
"deleteMany"
|
|
23
23
|
]);
|
|
24
24
|
function deterministicStringify(val) {
|
|
25
|
+
if (val instanceof Date) return `date:${JSON.stringify(val.toISOString())}`;
|
|
26
|
+
if (typeof val === "bigint") return `bigint:${val}`;
|
|
27
|
+
if (val instanceof Uint8Array) return `binary:${Buffer.from(val.buffer, val.byteOffset, val.byteLength).toString("base64")}`;
|
|
28
|
+
if (val && typeof val === "object" && typeof val.toJSON === "function") {
|
|
29
|
+
return deterministicStringify(val.toJSON());
|
|
30
|
+
}
|
|
25
31
|
if (val === null || typeof val !== "object") {
|
|
26
|
-
return JSON.stringify(val);
|
|
32
|
+
return JSON.stringify(val) ?? "undefined";
|
|
27
33
|
}
|
|
28
34
|
if (Array.isArray(val)) {
|
|
29
35
|
return `[${val.map(deterministicStringify).join(",")}]`;
|
|
@@ -54,6 +60,10 @@ function withTriCache(options) {
|
|
|
54
60
|
if (READ_OPERATIONS.has(operation)) {
|
|
55
61
|
const queryArgs = args ?? {};
|
|
56
62
|
const cacheConfig = queryArgs.cache;
|
|
63
|
+
if (cacheConfig === false) {
|
|
64
|
+
const { cache: _c, ...cleanArgs } = queryArgs;
|
|
65
|
+
return query(cleanArgs);
|
|
66
|
+
}
|
|
57
67
|
if (cacheConfig !== void 0 || autoCache) {
|
|
58
68
|
const opts = typeof cacheConfig === "object" && cacheConfig !== null ? cacheConfig : {};
|
|
59
69
|
const { cache: _c, ...cleanArgs } = queryArgs;
|
|
@@ -215,13 +215,6 @@ declare function createMemorySnapshotAdapter(): IRemoteSnapshotAdapter & {
|
|
|
215
215
|
clear(): void;
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
-
/**
|
|
219
|
-
* tricache — Multi-Cluster / Geo-Distributed Cross-Region Invalidation Relay
|
|
220
|
-
*
|
|
221
|
-
* Enables multi-region architectures (e.g. us-east-1 + eu-central-1) with independent
|
|
222
|
-
* Redis clusters to synchronize invalidations across regions without expensive
|
|
223
|
-
* active-active Redis Enterprise licenses.
|
|
224
|
-
*/
|
|
225
218
|
interface CrossRegionInvalidationEvent {
|
|
226
219
|
/** Unique ID of this invalidation event (UUIDv4) */
|
|
227
220
|
id: string;
|
|
@@ -362,7 +355,7 @@ interface ICacheSpan {
|
|
|
362
355
|
code: 0 | 1 | 2;
|
|
363
356
|
message?: string;
|
|
364
357
|
}): this;
|
|
365
|
-
recordException?(err:
|
|
358
|
+
recordException?(err: unknown): void;
|
|
366
359
|
end(): void;
|
|
367
360
|
}
|
|
368
361
|
/**
|
|
@@ -446,6 +439,9 @@ interface SmartCacheEntry {
|
|
|
446
439
|
setAt?: number;
|
|
447
440
|
/** Active tag versions at write time (used when tagStrategy === 'generational') */
|
|
448
441
|
tagVersions?: Record<string, number>;
|
|
442
|
+
/** Set-based tags and dependency patterns preserved through disk/snapshot promotion. */
|
|
443
|
+
tags?: string[];
|
|
444
|
+
dependsOn?: string[];
|
|
449
445
|
}
|
|
450
446
|
/** Returned by SmartMemoryCache.get() — distinguishes "cached null" from a real miss */
|
|
451
447
|
interface CacheHit {
|
|
@@ -466,6 +462,8 @@ interface CacheHit {
|
|
|
466
462
|
tagVersions?: Record<string, number>;
|
|
467
463
|
/** Timestamp (ms) when this entry was written into memory */
|
|
468
464
|
setAt?: number;
|
|
465
|
+
tags?: string[];
|
|
466
|
+
dependsOn?: string[];
|
|
469
467
|
}
|
|
470
468
|
/** On-disk entry shape (mirrors SmartCacheEntry — Uint8Array accepted for msgpack round-trips;
|
|
471
469
|
* legacy disk files written by older versions may have a JSON string in data) */
|
|
@@ -480,6 +478,12 @@ interface DiskCacheEntry {
|
|
|
480
478
|
priority: number;
|
|
481
479
|
/** Active tag versions at write time (used when tagStrategy === 'generational') */
|
|
482
480
|
tagVersions?: Record<string, number>;
|
|
481
|
+
/** Original write time and TTL, preserved on spill and promotion. */
|
|
482
|
+
setAt?: number;
|
|
483
|
+
ttlMs?: number;
|
|
484
|
+
delta?: number;
|
|
485
|
+
tags?: string[];
|
|
486
|
+
dependsOn?: string[];
|
|
483
487
|
}
|
|
484
488
|
/**
|
|
485
489
|
* Snapshot of runtime metrics for a CacheService instance.
|
|
@@ -1404,8 +1408,12 @@ interface LockOptions {
|
|
|
1404
1408
|
interface ICacheCounter {
|
|
1405
1409
|
add(value: number, attributes?: Record<string, string | number | boolean>): void;
|
|
1406
1410
|
}
|
|
1411
|
+
type ICacheObservableCallback = (result: {
|
|
1412
|
+
observe(value: number, attributes?: Record<string, string | number | boolean>): void;
|
|
1413
|
+
}) => void | Promise<void>;
|
|
1407
1414
|
interface ICacheObservableGauge {
|
|
1408
|
-
|
|
1415
|
+
addCallback(callback: ICacheObservableCallback): void;
|
|
1416
|
+
removeCallback(callback: ICacheObservableCallback): void;
|
|
1409
1417
|
}
|
|
1410
1418
|
interface ICacheBatchObservableCallback {
|
|
1411
1419
|
(observableResult: {
|
|
@@ -1422,6 +1430,7 @@ interface ICacheMeter {
|
|
|
1422
1430
|
unit?: string;
|
|
1423
1431
|
}): ICacheObservableGauge;
|
|
1424
1432
|
addBatchObservableCallback(callback: ICacheBatchObservableCallback, observables: ICacheObservableGauge[]): void;
|
|
1433
|
+
removeBatchObservableCallback?(callback: ICacheBatchObservableCallback, observables: ICacheObservableGauge[]): void;
|
|
1425
1434
|
}
|
|
1426
1435
|
/**
|
|
1427
1436
|
* Common pipeline / transaction interface matching ioredis and adapted drivers.
|
|
@@ -1437,6 +1446,9 @@ interface IRedisPipeline {
|
|
|
1437
1446
|
smembers(key: string): this;
|
|
1438
1447
|
hset(key: string, value: Record<string, string>): this;
|
|
1439
1448
|
hgetall?(key: string): this;
|
|
1449
|
+
/** Remaining TTL in milliseconds; enables atomic value + expiry reads. */
|
|
1450
|
+
pttl?(key: string): this;
|
|
1451
|
+
eval?(script: string, numkeys: number, ...args: (string | number)[]): this;
|
|
1440
1452
|
exec(): Promise<Array<[Error | null, any]> | null>;
|
|
1441
1453
|
}
|
|
1442
1454
|
/**
|
|
@@ -1449,6 +1461,7 @@ interface IRedisDriver {
|
|
|
1449
1461
|
setex?(key: string, seconds: number, value: string): Promise<unknown>;
|
|
1450
1462
|
del(...keys: string[]): Promise<number>;
|
|
1451
1463
|
ping(): Promise<string>;
|
|
1464
|
+
pttl?(key: string): Promise<number>;
|
|
1452
1465
|
expire(key: string, seconds: number): Promise<number | boolean>;
|
|
1453
1466
|
incr(key: string): Promise<number>;
|
|
1454
1467
|
eval(script: string, numkeys: number, ...args: (string | number)[]): Promise<unknown>;
|
|
@@ -1465,6 +1478,8 @@ interface IRedisDriver {
|
|
|
1465
1478
|
hgetall?(key: string): Promise<Record<string, string>>;
|
|
1466
1479
|
publish?(channel: string, message: string): Promise<number>;
|
|
1467
1480
|
subscribe?(...channels: string[]): Promise<unknown>;
|
|
1481
|
+
unsubscribe?(...channels: string[]): Promise<unknown>;
|
|
1482
|
+
removeListener?(event: string, listener: (...args: any[]) => void): this | unknown;
|
|
1468
1483
|
disconnect(): Promise<void> | void;
|
|
1469
1484
|
quit?(): Promise<void> | void;
|
|
1470
1485
|
duplicate?(): IRedisDriver;
|