tricache 0.6.7 → 0.7.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.
- package/LICENSE +1 -1
- package/README.md +1428 -970
- package/bin/tricache.js +8 -0
- package/dist/cache-service-5GATUYAK.js +7 -0
- package/dist/cache-service-D8tIXmzb.d.ts +1498 -0
- package/dist/chunk-EUGYR7KR.js +4629 -0
- package/dist/chunk-UBSR5UYA.js +0 -0
- package/dist/{chunk-FKY5R3CE.js → chunk-X5AXHPVD.js} +139 -6
- package/dist/cli.cjs +5238 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +130 -0
- package/dist/drizzle/index.cjs +5218 -0
- package/dist/drizzle/index.d.ts +44 -0
- package/dist/drizzle/index.js +46 -0
- package/dist/http/index.cjs +5374 -0
- package/dist/http/index.d.ts +33 -0
- package/dist/http/index.js +200 -0
- package/dist/index.cjs +1245 -209
- package/dist/index.d.ts +15 -1230
- package/dist/index.js +11 -3705
- package/dist/nestjs/index.cjs +5362 -0
- package/dist/nestjs/index.d.ts +210 -0
- package/dist/nestjs/index.js +250 -0
- package/dist/next/index.cjs +5407 -0
- package/dist/next/index.d.ts +208 -0
- package/dist/next/index.js +297 -0
- package/dist/prisma/index.cjs +123 -0
- package/dist/prisma/index.d.ts +60 -0
- package/dist/prisma/index.js +87 -0
- package/dist/serialize-worker.cjs +190 -15
- package/dist/serialize-worker.js +63 -12
- package/package.json +71 -21
- package/src/cache-service.ts +3294 -2429
- package/src/cli.ts +143 -0
- package/src/compression.ts +56 -0
- package/src/disk-tier.ts +821 -757
- package/src/drizzle/index.ts +86 -0
- package/src/encryption.ts +513 -442
- package/src/http/index.ts +265 -0
- package/src/index.ts +7 -0
- package/src/nestjs/decorators.ts +161 -0
- package/src/nestjs/index.ts +23 -0
- package/src/nestjs/tricache.module.ts +104 -0
- package/src/nestjs/tricache.store.ts +97 -0
- package/src/nestjs/types.ts +79 -0
- package/src/next/cache-handler.ts +268 -0
- package/src/next/index.ts +37 -0
- package/src/next/isr-handler.ts +105 -0
- package/src/next/types.ts +130 -0
- package/src/prisma/index.ts +154 -0
- package/src/serialize-worker.ts +77 -13
- package/src/smart-memory-cache.ts +1026 -1010
- package/src/types.ts +911 -732
- package/src/wasm/bloom-filter-wasm.ts +3 -2
- package/src/worker-pool.ts +156 -42
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TriCache CLI — Developer & Troubleshooting Inspector
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* npx tricache inspect [--redis redis://localhost:6379] [--namespace <ns>]
|
|
6
|
+
* npx tricache ping [--redis redis://localhost:6379]
|
|
7
|
+
* npx tricache clear [--redis redis://localhost:6379] [--namespace <ns>] [--prefix <prefix>]
|
|
8
|
+
*/
|
|
9
|
+
declare function runCli(args?: string[]): Promise<void>;
|
|
10
|
+
|
|
11
|
+
export { runCli };
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CacheService
|
|
3
|
+
} from "./chunk-EUGYR7KR.js";
|
|
4
|
+
import "./chunk-X5AXHPVD.js";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
import { parseArgs } from "util";
|
|
8
|
+
async function runCli(args = process.argv.slice(2)) {
|
|
9
|
+
const options = {
|
|
10
|
+
redis: { type: "string", short: "r" },
|
|
11
|
+
port: { type: "string", short: "p" },
|
|
12
|
+
namespace: { type: "string", short: "n" },
|
|
13
|
+
prefix: { type: "string" },
|
|
14
|
+
disk: { type: "string", short: "d" },
|
|
15
|
+
help: { type: "boolean", short: "h" },
|
|
16
|
+
version: { type: "boolean", short: "v" }
|
|
17
|
+
};
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = parseArgs({
|
|
21
|
+
args,
|
|
22
|
+
options,
|
|
23
|
+
allowPositionals: true,
|
|
24
|
+
strict: false
|
|
25
|
+
});
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error(`Error: ${err.message}
|
|
28
|
+
`);
|
|
29
|
+
printHelp();
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
const { values, positionals } = parsed;
|
|
33
|
+
const command = positionals[0] || "inspect";
|
|
34
|
+
if (values.help || command === "help") {
|
|
35
|
+
printHelp();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (values.version || command === "version") {
|
|
39
|
+
console.log("tricache v0.7.1");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const redisStr = typeof values.redis === "string" ? values.redis : void 0;
|
|
43
|
+
const redisHost = redisStr ? redisStr.replace(/^redis:\/\//, "").split(":")[0] : void 0;
|
|
44
|
+
const redisPort = typeof values.port === "string" ? parseInt(values.port, 10) : redisStr && redisStr.includes(":") ? parseInt(redisStr.split(":")[1], 10) : 6379;
|
|
45
|
+
const namespace = typeof values.namespace === "string" ? values.namespace : void 0;
|
|
46
|
+
const diskCacheDir = typeof values.disk === "string" ? values.disk : void 0;
|
|
47
|
+
const cache = new CacheService({
|
|
48
|
+
redisHost,
|
|
49
|
+
redisPort,
|
|
50
|
+
namespace,
|
|
51
|
+
diskCacheDir,
|
|
52
|
+
disableRedis: !redisHost
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
if (command === "inspect") {
|
|
56
|
+
const ping = await cache.ping();
|
|
57
|
+
const metrics = cache.metrics();
|
|
58
|
+
const stats = cache.stats();
|
|
59
|
+
const hot = cache.hotKeys(5);
|
|
60
|
+
const divPct = (n) => `${(n * 100).toFixed(1)}%`;
|
|
61
|
+
const l1MaxKB = Math.round((cache.options.l1MaxBytes ?? 200 * 1024 * 1024) / 1024);
|
|
62
|
+
console.log(`
|
|
63
|
+
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
64
|
+
\u2502 TriCache Engine Dashboard (Namespace: ${namespace || "(default)"})
|
|
65
|
+
\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524
|
|
66
|
+
\u2502 Tiers Active: L1 (RAM) \u2192 L1.5 (NVMe Disk) \u2192 L2 (${redisHost ? "Redis" : "Disabled"})
|
|
67
|
+
\u2502 Latencies: L1: ${ping.l1}ms | Disk: ${ping.disk}ms | L2: ${ping.l2 !== null ? `${ping.l2}ms` : "N/A"}
|
|
68
|
+
\u2502 L1 Entries: ${stats.l1.entries} (${stats.l1.sizeKB} KB / ${l1MaxKB} KB)
|
|
69
|
+
\u2502 Disk Files: ${stats.disk.files} (${stats.disk.sizeKB} KB / ${stats.disk.maxKB} KB)
|
|
70
|
+
\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524
|
|
71
|
+
\u2502 L1 Hit Ratio: ${divPct(metrics.gets.l1HitRate)} (${metrics.gets.l1Hits} hits)
|
|
72
|
+
\u2502 L2 Hit Ratio: ${divPct(metrics.gets.l2HitRate)} (${metrics.gets.l2Hits} hits)
|
|
73
|
+
\u2502 Disk Hit Ratio: ${divPct(metrics.gets.diskHitRate)} (${metrics.gets.diskHits} hits)
|
|
74
|
+
\u2502 Stampedes Saved: ${metrics.gets.stampedePrevented} coalesced requests
|
|
75
|
+
\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524
|
|
76
|
+
\u2502 \u{1F525} Top Hot Keys (Count-Min Sketch):`);
|
|
77
|
+
if (hot.length === 0) {
|
|
78
|
+
console.log("\u2502 (no hot keys recorded yet)");
|
|
79
|
+
} else {
|
|
80
|
+
hot.forEach(({ key, hits, sizeBytes }, idx) => {
|
|
81
|
+
const size = sizeBytes > 1024 ? `${(sizeBytes / 1024).toFixed(1)} KB` : `${sizeBytes} B`;
|
|
82
|
+
console.log(`\u2502 ${idx + 1}. ${key.padEnd(24)} (${hits} hits, ${size})`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n");
|
|
86
|
+
} else if (command === "ping") {
|
|
87
|
+
const ping = await cache.ping();
|
|
88
|
+
console.log(`TriCache Ping Results:`);
|
|
89
|
+
console.log(` \u2022 L1 RAM: ${ping.l1}ms`);
|
|
90
|
+
console.log(` \u2022 Disk: ${ping.disk}ms`);
|
|
91
|
+
console.log(` \u2022 L2 Redis:${ping.l2 !== null ? ` ${ping.l2}ms` : " Disabled"}`);
|
|
92
|
+
} else if (command === "clear") {
|
|
93
|
+
const prefix = typeof values.prefix === "string" ? values.prefix : void 0;
|
|
94
|
+
await cache.clear(prefix);
|
|
95
|
+
console.log(`Cleared cache${prefix ? ` for prefix "${prefix}"` : " (all entries)"} in namespace "${namespace || "(default)"}".`);
|
|
96
|
+
} else {
|
|
97
|
+
console.error(`Unknown command: ${command}
|
|
98
|
+
`);
|
|
99
|
+
printHelp();
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
} finally {
|
|
103
|
+
await cache.destroy();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function printHelp() {
|
|
107
|
+
console.log(`
|
|
108
|
+
TriCache CLI \u2014 Developer & Troubleshooting Tool
|
|
109
|
+
|
|
110
|
+
Usage:
|
|
111
|
+
tricache <command> [options]
|
|
112
|
+
|
|
113
|
+
Commands:
|
|
114
|
+
inspect Display full dashboard including hit ratios, latencies, and hot keys (default)
|
|
115
|
+
ping Measure response latency across L1 (RAM), L1.5 (Disk), and L2 (Redis)
|
|
116
|
+
clear Flush all entries or keys matching a prefix
|
|
117
|
+
|
|
118
|
+
Options:
|
|
119
|
+
-r, --redis <host|url> Redis connection host or URL (e.g. localhost, redis://127.0.0.1:6379)
|
|
120
|
+
-p, --port <port> Redis port (default: 6379)
|
|
121
|
+
-n, --namespace <ns> Cache namespace
|
|
122
|
+
--prefix <prefix> Key prefix filter for clear command
|
|
123
|
+
-d, --disk <path> Custom disk cache directory path
|
|
124
|
+
-h, --help Show this help message
|
|
125
|
+
-v, --version Display version number
|
|
126
|
+
`);
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
runCli
|
|
130
|
+
};
|