tricache 0.6.6 → 0.7.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.
Files changed (55) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +500 -24
  3. package/bin/tricache.js +8 -0
  4. package/dist/cache-service-AJASH5FX.js +7 -0
  5. package/dist/cache-service-BblHuF3i.d.ts +1476 -0
  6. package/dist/chunk-3XQUQBOZ.js +4583 -0
  7. package/dist/{chunk-FKY5R3CE.js → chunk-PFB5FMEY.js} +126 -4
  8. package/dist/chunk-UBSR5UYA.js +0 -0
  9. package/dist/cli.cjs +5181 -0
  10. package/dist/cli.d.ts +11 -0
  11. package/dist/cli.js +130 -0
  12. package/dist/drizzle/index.cjs +5161 -0
  13. package/dist/drizzle/index.d.ts +44 -0
  14. package/dist/drizzle/index.js +46 -0
  15. package/dist/http/index.cjs +5289 -0
  16. package/dist/http/index.d.ts +33 -0
  17. package/dist/http/index.js +172 -0
  18. package/dist/index.cjs +1181 -194
  19. package/dist/index.d.ts +15 -1230
  20. package/dist/index.js +11 -3697
  21. package/dist/nestjs/index.cjs +5305 -0
  22. package/dist/nestjs/index.d.ts +210 -0
  23. package/dist/nestjs/index.js +250 -0
  24. package/dist/next/index.cjs +5327 -0
  25. package/dist/next/index.d.ts +204 -0
  26. package/dist/next/index.js +274 -0
  27. package/dist/prisma/index.cjs +122 -0
  28. package/dist/prisma/index.d.ts +60 -0
  29. package/dist/prisma/index.js +86 -0
  30. package/dist/serialize-worker.cjs +177 -13
  31. package/dist/serialize-worker.js +63 -12
  32. package/package.json +64 -15
  33. package/src/cache-service.ts +1005 -192
  34. package/src/cli.ts +143 -0
  35. package/src/compression.ts +63 -0
  36. package/src/disk-tier.ts +71 -7
  37. package/src/drizzle/index.ts +86 -0
  38. package/src/encryption.ts +56 -5
  39. package/src/http/index.ts +223 -0
  40. package/src/index.ts +7 -0
  41. package/src/nestjs/decorators.ts +161 -0
  42. package/src/nestjs/index.ts +23 -0
  43. package/src/nestjs/tricache.module.ts +104 -0
  44. package/src/nestjs/tricache.store.ts +97 -0
  45. package/src/nestjs/types.ts +79 -0
  46. package/src/next/cache-handler.ts +244 -0
  47. package/src/next/index.ts +37 -0
  48. package/src/next/isr-handler.ts +105 -0
  49. package/src/next/types.ts +130 -0
  50. package/src/prisma/index.ts +151 -0
  51. package/src/serialize-worker.ts +77 -13
  52. package/src/smart-memory-cache.ts +22 -8
  53. package/src/types.ts +172 -2
  54. package/src/wasm/bloom-filter-wasm.ts +3 -2
  55. 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-3XQUQBOZ.js";
4
+ import "./chunk-PFB5FMEY.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.0");
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
+ };