tricache 1.0.1 → 2.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 +89 -93
- package/dashboards/tricache-alerts.yaml +80 -4
- package/dashboards/tricache-grafana.json +54 -1
- package/dashboards/tricache-inventory.rules.yml +21 -0
- package/dist/cache-service-BV5T8-20.d.cts +1064 -0
- package/dist/cache-service-UZXOQGEY.js +14 -0
- package/dist/{cache-service-CREOp7MM.d.ts → cache-service-tpyrXvlH.d.ts} +157 -24
- package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/{chunk-2AJKEQMZ.js → chunk-KV7KISK2.js} +54 -5
- package/dist/{chunk-JYQFQJNJ.js → chunk-MB3DMVWN.js} +3424 -1022
- package/dist/chunk-RBJRTGFK.js +94 -0
- package/dist/chunk-S5N65I45.js +17 -0
- package/dist/cli.cjs +3694 -1070
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +210 -14
- 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 +3578 -1068
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +6 -2
- package/dist/edge/index.cjs +368 -162
- package/dist/edge/index.d.cts +134 -0
- package/dist/edge/index.d.ts +11 -4
- package/dist/edge/index.js +314 -155
- package/dist/hono/index.cjs +3614 -1087
- 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-CMv2VdQ6.d.cts +404 -0
- package/dist/{hono-DSV2ve66.d.ts → hono-Dvq04kX9.d.ts} +33 -7
- package/dist/http/index.cjs +3712 -1124
- 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 +4067 -1252
- package/dist/index.d.cts +1071 -0
- package/dist/index.d.ts +123 -27
- package/dist/index.js +878 -21
- package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.cts} +1 -0
- package/dist/murmur3-DF8BFRnu.d.ts +99 -0
- package/dist/nestjs/index.cjs +3635 -1112
- package/dist/nestjs/index.d.cts +299 -0
- package/dist/nestjs/index.d.ts +120 -33
- package/dist/nestjs/index.js +132 -43
- package/dist/next/index.cjs +3704 -1175
- package/dist/next/index.d.cts +238 -0
- package/dist/next/index.d.ts +39 -11
- package/dist/next/index.js +202 -102
- package/dist/prisma/index.cjs +29 -18
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +17 -18
- package/dist/serialize-worker.cjs +162 -39
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/serialize-worker.js +9 -7
- package/dist/{types-Dyip5wAl.d.ts → types-F8vRWMrE.d.cts} +186 -54
- package/dist/types-F8vRWMrE.d.ts +1636 -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 +116 -37
- package/src/adapters/auto-pipeliner.ts +150 -26
- package/src/adapters/node-redis.ts +106 -27
- package/src/cache-service.ts +2215 -793
- package/src/cli.ts +25 -14
- package/src/codec.ts +3 -3
- package/src/compression.ts +39 -16
- package/src/cross-region.ts +22 -4
- 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 +448 -102
- package/src/drizzle/index.ts +2 -1
- package/src/edge/adapters/cloudflare-do.ts +25 -10
- package/src/edge/adapters/cloudflare-kv.ts +12 -9
- package/src/edge/adapters/upstash.ts +27 -11
- package/src/edge/cache.ts +200 -110
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +17 -5
- package/src/encryption.ts +50 -18
- package/src/env.d.ts +1 -1
- package/src/errors.ts +12 -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 +60 -20
- package/src/index.ts +6 -0
- package/src/ipc-telemetry.ts +35 -9
- package/src/latency-watchdog.ts +5 -1
- package/src/nestjs/decorators.ts +11 -6
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +15 -12
- package/src/nestjs/tricache.store.ts +69 -26
- package/src/nestjs/types.ts +30 -16
- package/src/next/cache-handler.ts +151 -53
- package/src/next/index.ts +1 -0
- package/src/next/types.ts +25 -0
- package/src/origin-capacity.ts +134 -0
- package/src/prisma/index.ts +17 -24
- package/src/remote-snapshot.ts +37 -27
- package/src/serialize-worker.ts +8 -5
- package/src/sigv4-snapshot-adapter.ts +37 -27
- package/src/smart-memory-cache.ts +121 -44
- package/src/types.ts +117 -37
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/config-comparison.ts +29 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -0
- package/src/utils/lz4-size.ts +74 -0
- package/src/utils/namespace-key.ts +48 -0
- package/src/utils/query-key.ts +13 -0
- package/src/utils/redis-slot.ts +13 -0
- package/src/utils/snapshot-transfer.ts +83 -0
- package/src/utils/work-limits.ts +73 -0
- package/src/utils/write-revision.ts +4 -0
- package/src/wasm/bloom-filter-wasm.ts +25 -5
- package/src/worker-pool.ts +44 -15
- package/src/wtiny-lfu.ts +82 -20
- package/dist/cache-service-MG7PN6MX.js +0 -12
- package/dist/chunk-3I5L7K6I.js +0 -704
- package/dist/chunk-BQRURGGD.js +0 -60
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { C as CacheOptions, f as CachePriority } from '../types-F8vRWMrE.cjs';
|
|
2
|
+
import { C as CacheService } from '../cache-service-BV5T8-20.cjs';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
import 'crypto';
|
|
5
|
+
|
|
6
|
+
declare const TRICACHE_SERVICE = "TRICACHE_SERVICE";
|
|
7
|
+
declare const CACHE_MANAGER = "CACHE_MANAGER";
|
|
8
|
+
type InjectionToken = string | symbol | Function | Type<any>;
|
|
9
|
+
interface Type<T = unknown> extends Function {
|
|
10
|
+
new (...args: any[]): T;
|
|
11
|
+
}
|
|
12
|
+
interface ForwardReference<T = unknown> {
|
|
13
|
+
forwardRef: () => T;
|
|
14
|
+
}
|
|
15
|
+
interface Abstract<T> extends Function {
|
|
16
|
+
prototype: T;
|
|
17
|
+
}
|
|
18
|
+
interface ValueProvider<T = unknown> {
|
|
19
|
+
provide: InjectionToken;
|
|
20
|
+
useValue: T;
|
|
21
|
+
}
|
|
22
|
+
interface ClassProvider<T = unknown> {
|
|
23
|
+
provide: InjectionToken;
|
|
24
|
+
useClass: Type<T>;
|
|
25
|
+
scope?: 0 | 1 | 2;
|
|
26
|
+
durable?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface ExistingProvider {
|
|
29
|
+
provide: InjectionToken;
|
|
30
|
+
useExisting: InjectionToken;
|
|
31
|
+
}
|
|
32
|
+
interface FactoryProvider<T = unknown> {
|
|
33
|
+
provide: InjectionToken;
|
|
34
|
+
useFactory: (...args: any[]) => T | Promise<T>;
|
|
35
|
+
inject?: Array<InjectionToken | {
|
|
36
|
+
token: InjectionToken;
|
|
37
|
+
optional: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
scope?: 0 | 1 | 2;
|
|
40
|
+
durable?: boolean;
|
|
41
|
+
}
|
|
42
|
+
type Provider<T = unknown> = Type<unknown> | ValueProvider<T> | ClassProvider<T> | ExistingProvider | FactoryProvider<T>;
|
|
43
|
+
interface DynamicModule {
|
|
44
|
+
module: Type<any>;
|
|
45
|
+
providers?: Provider[];
|
|
46
|
+
exports?: Array<DynamicModule | string | symbol | Provider | ForwardReference | Abstract<any> | Function>;
|
|
47
|
+
imports?: Array<Type<any> | DynamicModule | ForwardReference>;
|
|
48
|
+
controllers?: Type<any>[];
|
|
49
|
+
global?: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface TriCacheOptionsFactory {
|
|
52
|
+
createTriCacheOptions(): Promise<CacheOptions> | CacheOptions;
|
|
53
|
+
}
|
|
54
|
+
interface TriCacheAsyncOptions {
|
|
55
|
+
imports?: Array<Type<any> | DynamicModule | ForwardReference>;
|
|
56
|
+
useExisting?: InjectionToken;
|
|
57
|
+
useClass?: Type<TriCacheOptionsFactory>;
|
|
58
|
+
useFactory?: (...args: any[]) => Promise<CacheOptions> | CacheOptions;
|
|
59
|
+
inject?: Array<InjectionToken | {
|
|
60
|
+
token: InjectionToken;
|
|
61
|
+
optional: boolean;
|
|
62
|
+
}>;
|
|
63
|
+
extraProviders?: Provider[];
|
|
64
|
+
/** Whether to bind CACHE_MANAGER to TriCacheStore. Default: true. */
|
|
65
|
+
provideCacheManager?: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface TriCacheModuleOptions {
|
|
68
|
+
/** Set false when importing @nestjs/cache-manager CacheModule in the same application. Default: true. */
|
|
69
|
+
provideCacheManager?: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface NestCacheStore {
|
|
72
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
73
|
+
set<T>(key: string, value: T, ttl?: number): Promise<T>;
|
|
74
|
+
del(key: string): Promise<boolean>;
|
|
75
|
+
reset(): Promise<boolean>;
|
|
76
|
+
mget<T>(keys: string[]): Promise<(T | undefined)[]>;
|
|
77
|
+
mget<T>(...keys: string[]): Promise<(T | undefined)[]>;
|
|
78
|
+
mset(entries: Array<{
|
|
79
|
+
key: string;
|
|
80
|
+
value: unknown;
|
|
81
|
+
ttl?: number;
|
|
82
|
+
}>): Promise<Array<{
|
|
83
|
+
key: string;
|
|
84
|
+
value: unknown;
|
|
85
|
+
ttl?: number;
|
|
86
|
+
}>>;
|
|
87
|
+
mdel(keys: string[]): Promise<boolean>;
|
|
88
|
+
mdel(...keys: string[]): Promise<boolean>;
|
|
89
|
+
keys(pattern?: string): Promise<string[]>;
|
|
90
|
+
ttl(key: string): Promise<number | undefined>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* TriCacheModule — NestJS dynamic module providing TriCacheService and standard CacheStore.
|
|
95
|
+
*
|
|
96
|
+
* Can be registered synchronously via `TriCacheModule.register(options)`
|
|
97
|
+
* or asynchronously via `TriCacheModule.registerAsync({ useFactory: ... })`.
|
|
98
|
+
*
|
|
99
|
+
* Exports:
|
|
100
|
+
* - `TRICACHE_SERVICE` (`CacheService` instance)
|
|
101
|
+
* - `CACHE_MANAGER` (`TriCacheStore` adapter conforming to @nestjs/cache-manager)
|
|
102
|
+
*/
|
|
103
|
+
declare class TriCacheModule {
|
|
104
|
+
/**
|
|
105
|
+
* Register TriCache module synchronously with static configuration options.
|
|
106
|
+
*/
|
|
107
|
+
static register(options?: CacheOptions, moduleOptions?: TriCacheModuleOptions): DynamicModule;
|
|
108
|
+
/**
|
|
109
|
+
* Register TriCache module asynchronously with factory or class injection.
|
|
110
|
+
*/
|
|
111
|
+
static registerAsync(asyncOptions: TriCacheAsyncOptions): DynamicModule;
|
|
112
|
+
private static createAsyncProviders;
|
|
113
|
+
private static createAsyncOptionsProvider;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* TriCacheStore — Nest CACHE_MANAGER facade for CacheInterceptor and basic cache calls.
|
|
118
|
+
*
|
|
119
|
+
* Implements millisecond-based TTL semantics for cache-manager v7's common API
|
|
120
|
+
* while dispatching to TriCache's three-tier engine with L1 memory, L1.5 disk spill,
|
|
121
|
+
* and L2 Redis/Valkey tiers.
|
|
122
|
+
*/
|
|
123
|
+
declare class TriCacheStore extends EventEmitter implements NestCacheStore {
|
|
124
|
+
readonly cache: CacheService;
|
|
125
|
+
constructor(cache: CacheService);
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve an item from the cache.
|
|
128
|
+
* Returns undefined on miss (matching Keyv/cache-manager contract).
|
|
129
|
+
*/
|
|
130
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
131
|
+
get<T>(key: string, options: {
|
|
132
|
+
raw: true;
|
|
133
|
+
}): Promise<{
|
|
134
|
+
value: T;
|
|
135
|
+
expires?: number;
|
|
136
|
+
} | undefined>;
|
|
137
|
+
/**
|
|
138
|
+
* Set an item in the cache.
|
|
139
|
+
* @param key - Cache key
|
|
140
|
+
* @param value - Cache value
|
|
141
|
+
* @param ttl - TTL in milliseconds. Omitted uses the engine default (300 s);
|
|
142
|
+
* `0` means indefinite; positive values are converted to seconds.
|
|
143
|
+
*/
|
|
144
|
+
set<T>(key: string, value: T, ttl?: number): Promise<T>;
|
|
145
|
+
/**
|
|
146
|
+
* Remove an item from the cache.
|
|
147
|
+
*/
|
|
148
|
+
del(key: string): Promise<boolean>;
|
|
149
|
+
/**
|
|
150
|
+
* Clear the entire cache namespace.
|
|
151
|
+
*/
|
|
152
|
+
reset(): Promise<boolean>;
|
|
153
|
+
/**
|
|
154
|
+
* Batch get multiple items from the cache. Accepts cache-manager 7's key array
|
|
155
|
+
* and the legacy cache-store variadic form.
|
|
156
|
+
*/
|
|
157
|
+
mget<T>(keys: string[]): Promise<(T | undefined)[]>;
|
|
158
|
+
mget<T>(...keys: string[]): Promise<(T | undefined)[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Batch set multiple entries with per-entry millisecond TTL.
|
|
161
|
+
*/
|
|
162
|
+
mset(entries: Array<{
|
|
163
|
+
key: string;
|
|
164
|
+
value: unknown;
|
|
165
|
+
ttl?: number;
|
|
166
|
+
}>): Promise<Array<{
|
|
167
|
+
key: string;
|
|
168
|
+
value: unknown;
|
|
169
|
+
ttl?: number;
|
|
170
|
+
}>>;
|
|
171
|
+
/**
|
|
172
|
+
* Batch delete multiple keys.
|
|
173
|
+
*/
|
|
174
|
+
mdel(keys: string[]): Promise<boolean>;
|
|
175
|
+
mdel(...keys: string[]): Promise<boolean>;
|
|
176
|
+
/**
|
|
177
|
+
* Scan keys currently resident in the cache.
|
|
178
|
+
*/
|
|
179
|
+
keys(pattern?: string): Promise<string[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Get remaining TTL for a key in milliseconds.
|
|
182
|
+
*/
|
|
183
|
+
ttl(key: string): Promise<number | undefined>;
|
|
184
|
+
wrap<T>(key: string, fetch: () => T | Promise<T>, ttl?: number, refreshThreshold?: number): Promise<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Translate a cache-manager millisecond TTL into engine seconds using the same
|
|
187
|
+
* contract as `set()`: omitted keeps the engine default, `0` means indefinite,
|
|
188
|
+
* and positive values convert exactly (sub-second values round up).
|
|
189
|
+
*/
|
|
190
|
+
private _ttlSeconds;
|
|
191
|
+
cacheId(): string;
|
|
192
|
+
get stores(): unknown[];
|
|
193
|
+
clear(): Promise<boolean>;
|
|
194
|
+
disconnect(): Promise<undefined>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Relative-millisecond storage adapter for Keyv 5 / cache-manager 7.
|
|
199
|
+
* Wrap it in Keyv before passing it to Nest's CacheModule. Unlike TriCacheStore,
|
|
200
|
+
* this is a storage adapter, not the injected cache-manager facade.
|
|
201
|
+
* The supplied engine remains caller-owned when Keyv disconnects.
|
|
202
|
+
*/
|
|
203
|
+
declare class TriCacheKeyvAdapter extends EventEmitter {
|
|
204
|
+
readonly cache: CacheService;
|
|
205
|
+
private _namespace?;
|
|
206
|
+
constructor(cache: CacheService);
|
|
207
|
+
get namespace(): string | undefined;
|
|
208
|
+
set namespace(value: string | undefined);
|
|
209
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
210
|
+
set(key: string, value: unknown, ttl?: number): Promise<boolean>;
|
|
211
|
+
delete(key: string): Promise<boolean>;
|
|
212
|
+
clear(): Promise<void>;
|
|
213
|
+
has(key: string): Promise<boolean>;
|
|
214
|
+
getMany<T = unknown>(keys: string[]): Promise<(T | undefined)[]>;
|
|
215
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
216
|
+
setMany(entries: Array<{
|
|
217
|
+
key: string;
|
|
218
|
+
value: unknown;
|
|
219
|
+
ttl?: number;
|
|
220
|
+
}>): Promise<boolean[]>;
|
|
221
|
+
hasMany(keys: string[]): Promise<boolean[]>;
|
|
222
|
+
disconnect(): Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
interface CacheableOptions {
|
|
226
|
+
/**
|
|
227
|
+
* Static key string or dynamic key generator function.
|
|
228
|
+
* Example: (id: string) => `user:${id}`
|
|
229
|
+
*/
|
|
230
|
+
key?: string | ((...args: any[]) => string);
|
|
231
|
+
/**
|
|
232
|
+
* TTL value. Unit is controlled by `ttlUnit` and defaults to seconds.
|
|
233
|
+
* Default: 300 s.
|
|
234
|
+
*/
|
|
235
|
+
ttl?: number;
|
|
236
|
+
/**
|
|
237
|
+
* Explicit time unit for `ttl`. Default: `'seconds'`.
|
|
238
|
+
* There is no implicit unit detection: `ttl: 5000` is 5,000 seconds unless
|
|
239
|
+
* `ttlUnit: 'milliseconds'` is set.
|
|
240
|
+
*/
|
|
241
|
+
ttlUnit?: 'seconds' | 'milliseconds';
|
|
242
|
+
/** Stale-While-Revalidate grace period in seconds. */
|
|
243
|
+
swr?: number;
|
|
244
|
+
/** Semantic tags for invalidation. */
|
|
245
|
+
tags?: string[] | ((...args: any[]) => string[]);
|
|
246
|
+
/** Dependency cascade patterns. */
|
|
247
|
+
dependsOn?: string[] | ((...args: any[]) => string[]);
|
|
248
|
+
/** Cache eviction priority. */
|
|
249
|
+
priority?: CachePriority;
|
|
250
|
+
/** 0–1 fraction of TTL elapsed for background recompute. */
|
|
251
|
+
refreshAhead?: number;
|
|
252
|
+
/** XFetch probabilistic early expiration factor (0.5–2.0). */
|
|
253
|
+
xfetchBeta?: number;
|
|
254
|
+
/** Condition predicate to determine whether caching should occur. */
|
|
255
|
+
condition?: (...args: any[]) => boolean;
|
|
256
|
+
}
|
|
257
|
+
interface CacheEvictOptions {
|
|
258
|
+
/** Key or pattern to delete. */
|
|
259
|
+
key?: string | ((...args: any[]) => string);
|
|
260
|
+
/** Tags to invalidate. */
|
|
261
|
+
tags?: string[] | ((...args: any[]) => string[]);
|
|
262
|
+
/** Invalidate before method execution (default: false = after successful execution). */
|
|
263
|
+
beforeInvocation?: boolean;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Declarative method decorator that caches the return value of an async method.
|
|
267
|
+
*
|
|
268
|
+
* Automatically intercepts calls, checks TriCache (L1 -> L1.5 -> L2), and falls
|
|
269
|
+
* back to executing the decorated method on cache miss with thundering-herd protection.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* @Injectable()
|
|
274
|
+
* export class UserService {
|
|
275
|
+
* @Cacheable({ key: (id) => `user:${id}`, ttl: 300, tags: ['users'] })
|
|
276
|
+
* async findById(id: string) {
|
|
277
|
+
* return this.db.find(id);
|
|
278
|
+
* }
|
|
279
|
+
* }
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
declare function Cacheable(options?: CacheableOptions): MethodDecorator;
|
|
283
|
+
/**
|
|
284
|
+
* Declarative method decorator that invalidates cache keys or tags upon method execution.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* @Injectable()
|
|
289
|
+
* export class UserService {
|
|
290
|
+
* @CacheEvict({ tags: ['users'] })
|
|
291
|
+
* async update(id: string, dto: UpdateUserDto) {
|
|
292
|
+
* return this.db.update(id, dto);
|
|
293
|
+
* }
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
declare function CacheEvict(options?: CacheEvictOptions): MethodDecorator;
|
|
298
|
+
|
|
299
|
+
export { CACHE_MANAGER, CacheEvict, type CacheEvictOptions, Cacheable, type CacheableOptions, type DynamicModule, type InjectionToken, type NestCacheStore, type Provider, TRICACHE_SERVICE, type TriCacheAsyncOptions, TriCacheKeyvAdapter, TriCacheModule, type TriCacheModuleOptions, type TriCacheOptionsFactory, TriCacheStore, type Type, TriCacheModule as default };
|
package/dist/nestjs/index.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { C as CacheOptions, f as CachePriority } from '../types-
|
|
2
|
-
import { C as CacheService } from '../cache-service-
|
|
1
|
+
import { C as CacheOptions, f as CachePriority } from '../types-F8vRWMrE.js';
|
|
2
|
+
import { C as CacheService } from '../cache-service-tpyrXvlH.js';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
3
4
|
import 'crypto';
|
|
4
5
|
|
|
5
6
|
declare const TRICACHE_SERVICE = "TRICACHE_SERVICE";
|
|
6
7
|
declare const CACHE_MANAGER = "CACHE_MANAGER";
|
|
7
|
-
type InjectionToken = string | symbol | Function | Type<
|
|
8
|
+
type InjectionToken = string | symbol | Function | Type<any>;
|
|
8
9
|
interface Type<T = unknown> extends Function {
|
|
9
|
-
new (...args:
|
|
10
|
+
new (...args: any[]): T;
|
|
10
11
|
}
|
|
11
12
|
interface ForwardReference<T = unknown> {
|
|
12
13
|
forwardRef: () => T;
|
|
13
14
|
}
|
|
15
|
+
interface Abstract<T> extends Function {
|
|
16
|
+
prototype: T;
|
|
17
|
+
}
|
|
14
18
|
interface ValueProvider<T = unknown> {
|
|
15
19
|
provide: InjectionToken;
|
|
16
20
|
useValue: T;
|
|
@@ -18,6 +22,8 @@ interface ValueProvider<T = unknown> {
|
|
|
18
22
|
interface ClassProvider<T = unknown> {
|
|
19
23
|
provide: InjectionToken;
|
|
20
24
|
useClass: Type<T>;
|
|
25
|
+
scope?: 0 | 1 | 2;
|
|
26
|
+
durable?: boolean;
|
|
21
27
|
}
|
|
22
28
|
interface ExistingProvider {
|
|
23
29
|
provide: InjectionToken;
|
|
@@ -26,39 +32,60 @@ interface ExistingProvider {
|
|
|
26
32
|
interface FactoryProvider<T = unknown> {
|
|
27
33
|
provide: InjectionToken;
|
|
28
34
|
useFactory: (...args: any[]) => T | Promise<T>;
|
|
29
|
-
inject?: Array<InjectionToken |
|
|
35
|
+
inject?: Array<InjectionToken | {
|
|
36
|
+
token: InjectionToken;
|
|
37
|
+
optional: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
scope?: 0 | 1 | 2;
|
|
40
|
+
durable?: boolean;
|
|
30
41
|
}
|
|
31
42
|
type Provider<T = unknown> = Type<unknown> | ValueProvider<T> | ClassProvider<T> | ExistingProvider | FactoryProvider<T>;
|
|
32
43
|
interface DynamicModule {
|
|
33
|
-
module: Type<
|
|
44
|
+
module: Type<any>;
|
|
34
45
|
providers?: Provider[];
|
|
35
|
-
exports?: Array<DynamicModule |
|
|
36
|
-
imports?: Array<Type<
|
|
46
|
+
exports?: Array<DynamicModule | string | symbol | Provider | ForwardReference | Abstract<any> | Function>;
|
|
47
|
+
imports?: Array<Type<any> | DynamicModule | ForwardReference>;
|
|
48
|
+
controllers?: Type<any>[];
|
|
37
49
|
global?: boolean;
|
|
38
50
|
}
|
|
39
51
|
interface TriCacheOptionsFactory {
|
|
40
52
|
createTriCacheOptions(): Promise<CacheOptions> | CacheOptions;
|
|
41
53
|
}
|
|
42
54
|
interface TriCacheAsyncOptions {
|
|
43
|
-
imports?: Array<Type<
|
|
44
|
-
useExisting?:
|
|
55
|
+
imports?: Array<Type<any> | DynamicModule | ForwardReference>;
|
|
56
|
+
useExisting?: InjectionToken;
|
|
45
57
|
useClass?: Type<TriCacheOptionsFactory>;
|
|
46
|
-
useFactory?: (...args:
|
|
47
|
-
inject?: Array<InjectionToken |
|
|
58
|
+
useFactory?: (...args: any[]) => Promise<CacheOptions> | CacheOptions;
|
|
59
|
+
inject?: Array<InjectionToken | {
|
|
60
|
+
token: InjectionToken;
|
|
61
|
+
optional: boolean;
|
|
62
|
+
}>;
|
|
48
63
|
extraProviders?: Provider[];
|
|
64
|
+
/** Whether to bind CACHE_MANAGER to TriCacheStore. Default: true. */
|
|
65
|
+
provideCacheManager?: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface TriCacheModuleOptions {
|
|
68
|
+
/** Set false when importing @nestjs/cache-manager CacheModule in the same application. Default: true. */
|
|
69
|
+
provideCacheManager?: boolean;
|
|
49
70
|
}
|
|
50
71
|
interface NestCacheStore {
|
|
51
72
|
get<T>(key: string): Promise<T | undefined>;
|
|
52
|
-
set<T>(key: string, value: T, ttl?: number): Promise<
|
|
53
|
-
del(key: string): Promise<
|
|
54
|
-
reset(): Promise<
|
|
73
|
+
set<T>(key: string, value: T, ttl?: number): Promise<T>;
|
|
74
|
+
del(key: string): Promise<boolean>;
|
|
75
|
+
reset(): Promise<boolean>;
|
|
76
|
+
mget<T>(keys: string[]): Promise<(T | undefined)[]>;
|
|
55
77
|
mget<T>(...keys: string[]): Promise<(T | undefined)[]>;
|
|
56
78
|
mset(entries: Array<{
|
|
57
79
|
key: string;
|
|
58
80
|
value: unknown;
|
|
59
81
|
ttl?: number;
|
|
60
|
-
}>): Promise<
|
|
61
|
-
|
|
82
|
+
}>): Promise<Array<{
|
|
83
|
+
key: string;
|
|
84
|
+
value: unknown;
|
|
85
|
+
ttl?: number;
|
|
86
|
+
}>>;
|
|
87
|
+
mdel(keys: string[]): Promise<boolean>;
|
|
88
|
+
mdel(...keys: string[]): Promise<boolean>;
|
|
62
89
|
keys(pattern?: string): Promise<string[]>;
|
|
63
90
|
ttl(key: string): Promise<number | undefined>;
|
|
64
91
|
}
|
|
@@ -77,7 +104,7 @@ declare class TriCacheModule {
|
|
|
77
104
|
/**
|
|
78
105
|
* Register TriCache module synchronously with static configuration options.
|
|
79
106
|
*/
|
|
80
|
-
static register(options?: CacheOptions): DynamicModule;
|
|
107
|
+
static register(options?: CacheOptions, moduleOptions?: TriCacheModuleOptions): DynamicModule;
|
|
81
108
|
/**
|
|
82
109
|
* Register TriCache module asynchronously with factory or class injection.
|
|
83
110
|
*/
|
|
@@ -87,38 +114,47 @@ declare class TriCacheModule {
|
|
|
87
114
|
}
|
|
88
115
|
|
|
89
116
|
/**
|
|
90
|
-
* TriCacheStore —
|
|
117
|
+
* TriCacheStore — Nest CACHE_MANAGER facade for CacheInterceptor and basic cache calls.
|
|
91
118
|
*
|
|
92
|
-
* Implements millisecond-based TTL semantics
|
|
93
|
-
* while dispatching to TriCache's three-tier engine with L1 memory, L1.5
|
|
119
|
+
* Implements millisecond-based TTL semantics for cache-manager v7's common API
|
|
120
|
+
* while dispatching to TriCache's three-tier engine with L1 memory, L1.5 disk spill,
|
|
94
121
|
* and L2 Redis/Valkey tiers.
|
|
95
122
|
*/
|
|
96
|
-
declare class TriCacheStore implements NestCacheStore {
|
|
123
|
+
declare class TriCacheStore extends EventEmitter implements NestCacheStore {
|
|
97
124
|
readonly cache: CacheService;
|
|
98
125
|
constructor(cache: CacheService);
|
|
99
126
|
/**
|
|
100
127
|
* Retrieve an item from the cache.
|
|
101
|
-
* Returns undefined on miss (matching cache-manager
|
|
128
|
+
* Returns undefined on miss (matching Keyv/cache-manager contract).
|
|
102
129
|
*/
|
|
103
130
|
get<T>(key: string): Promise<T | undefined>;
|
|
131
|
+
get<T>(key: string, options: {
|
|
132
|
+
raw: true;
|
|
133
|
+
}): Promise<{
|
|
134
|
+
value: T;
|
|
135
|
+
expires?: number;
|
|
136
|
+
} | undefined>;
|
|
104
137
|
/**
|
|
105
138
|
* Set an item in the cache.
|
|
106
139
|
* @param key - Cache key
|
|
107
140
|
* @param value - Cache value
|
|
108
|
-
* @param ttl - TTL in milliseconds
|
|
141
|
+
* @param ttl - TTL in milliseconds. Omitted uses the engine default (300 s);
|
|
142
|
+
* `0` means indefinite; positive values are converted to seconds.
|
|
109
143
|
*/
|
|
110
|
-
set<T>(key: string, value: T, ttl?: number): Promise<
|
|
144
|
+
set<T>(key: string, value: T, ttl?: number): Promise<T>;
|
|
111
145
|
/**
|
|
112
146
|
* Remove an item from the cache.
|
|
113
147
|
*/
|
|
114
|
-
del(key: string): Promise<
|
|
148
|
+
del(key: string): Promise<boolean>;
|
|
115
149
|
/**
|
|
116
150
|
* Clear the entire cache namespace.
|
|
117
151
|
*/
|
|
118
|
-
reset(): Promise<
|
|
152
|
+
reset(): Promise<boolean>;
|
|
119
153
|
/**
|
|
120
|
-
* Batch get multiple items from the cache.
|
|
154
|
+
* Batch get multiple items from the cache. Accepts cache-manager 7's key array
|
|
155
|
+
* and the legacy cache-store variadic form.
|
|
121
156
|
*/
|
|
157
|
+
mget<T>(keys: string[]): Promise<(T | undefined)[]>;
|
|
122
158
|
mget<T>(...keys: string[]): Promise<(T | undefined)[]>;
|
|
123
159
|
/**
|
|
124
160
|
* Batch set multiple entries with per-entry millisecond TTL.
|
|
@@ -127,11 +163,16 @@ declare class TriCacheStore implements NestCacheStore {
|
|
|
127
163
|
key: string;
|
|
128
164
|
value: unknown;
|
|
129
165
|
ttl?: number;
|
|
130
|
-
}>): Promise<
|
|
166
|
+
}>): Promise<Array<{
|
|
167
|
+
key: string;
|
|
168
|
+
value: unknown;
|
|
169
|
+
ttl?: number;
|
|
170
|
+
}>>;
|
|
131
171
|
/**
|
|
132
172
|
* Batch delete multiple keys.
|
|
133
173
|
*/
|
|
134
|
-
mdel(
|
|
174
|
+
mdel(keys: string[]): Promise<boolean>;
|
|
175
|
+
mdel(...keys: string[]): Promise<boolean>;
|
|
135
176
|
/**
|
|
136
177
|
* Scan keys currently resident in the cache.
|
|
137
178
|
*/
|
|
@@ -140,6 +181,45 @@ declare class TriCacheStore implements NestCacheStore {
|
|
|
140
181
|
* Get remaining TTL for a key in milliseconds.
|
|
141
182
|
*/
|
|
142
183
|
ttl(key: string): Promise<number | undefined>;
|
|
184
|
+
wrap<T>(key: string, fetch: () => T | Promise<T>, ttl?: number, refreshThreshold?: number): Promise<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Translate a cache-manager millisecond TTL into engine seconds using the same
|
|
187
|
+
* contract as `set()`: omitted keeps the engine default, `0` means indefinite,
|
|
188
|
+
* and positive values convert exactly (sub-second values round up).
|
|
189
|
+
*/
|
|
190
|
+
private _ttlSeconds;
|
|
191
|
+
cacheId(): string;
|
|
192
|
+
get stores(): unknown[];
|
|
193
|
+
clear(): Promise<boolean>;
|
|
194
|
+
disconnect(): Promise<undefined>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Relative-millisecond storage adapter for Keyv 5 / cache-manager 7.
|
|
199
|
+
* Wrap it in Keyv before passing it to Nest's CacheModule. Unlike TriCacheStore,
|
|
200
|
+
* this is a storage adapter, not the injected cache-manager facade.
|
|
201
|
+
* The supplied engine remains caller-owned when Keyv disconnects.
|
|
202
|
+
*/
|
|
203
|
+
declare class TriCacheKeyvAdapter extends EventEmitter {
|
|
204
|
+
readonly cache: CacheService;
|
|
205
|
+
private _namespace?;
|
|
206
|
+
constructor(cache: CacheService);
|
|
207
|
+
get namespace(): string | undefined;
|
|
208
|
+
set namespace(value: string | undefined);
|
|
209
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
210
|
+
set(key: string, value: unknown, ttl?: number): Promise<boolean>;
|
|
211
|
+
delete(key: string): Promise<boolean>;
|
|
212
|
+
clear(): Promise<void>;
|
|
213
|
+
has(key: string): Promise<boolean>;
|
|
214
|
+
getMany<T = unknown>(keys: string[]): Promise<(T | undefined)[]>;
|
|
215
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
216
|
+
setMany(entries: Array<{
|
|
217
|
+
key: string;
|
|
218
|
+
value: unknown;
|
|
219
|
+
ttl?: number;
|
|
220
|
+
}>): Promise<boolean[]>;
|
|
221
|
+
hasMany(keys: string[]): Promise<boolean[]>;
|
|
222
|
+
disconnect(): Promise<void>;
|
|
143
223
|
}
|
|
144
224
|
|
|
145
225
|
interface CacheableOptions {
|
|
@@ -148,9 +228,16 @@ interface CacheableOptions {
|
|
|
148
228
|
* Example: (id: string) => `user:${id}`
|
|
149
229
|
*/
|
|
150
230
|
key?: string | ((...args: any[]) => string);
|
|
151
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* TTL value. Unit is controlled by `ttlUnit` and defaults to seconds.
|
|
233
|
+
* Default: 300 s.
|
|
234
|
+
*/
|
|
152
235
|
ttl?: number;
|
|
153
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Explicit time unit for `ttl`. Default: `'seconds'`.
|
|
238
|
+
* There is no implicit unit detection: `ttl: 5000` is 5,000 seconds unless
|
|
239
|
+
* `ttlUnit: 'milliseconds'` is set.
|
|
240
|
+
*/
|
|
154
241
|
ttlUnit?: 'seconds' | 'milliseconds';
|
|
155
242
|
/** Stale-While-Revalidate grace period in seconds. */
|
|
156
243
|
swr?: number;
|
|
@@ -209,4 +296,4 @@ declare function Cacheable(options?: CacheableOptions): MethodDecorator;
|
|
|
209
296
|
*/
|
|
210
297
|
declare function CacheEvict(options?: CacheEvictOptions): MethodDecorator;
|
|
211
298
|
|
|
212
|
-
export { CACHE_MANAGER, CacheEvict, type CacheEvictOptions, Cacheable, type CacheableOptions, type DynamicModule, type InjectionToken, type NestCacheStore, type Provider, TRICACHE_SERVICE, type TriCacheAsyncOptions, TriCacheModule, type TriCacheOptionsFactory, TriCacheStore, type Type, TriCacheModule as default };
|
|
299
|
+
export { CACHE_MANAGER, CacheEvict, type CacheEvictOptions, Cacheable, type CacheableOptions, type DynamicModule, type InjectionToken, type NestCacheStore, type Provider, TRICACHE_SERVICE, type TriCacheAsyncOptions, TriCacheKeyvAdapter, TriCacheModule, type TriCacheModuleOptions, type TriCacheOptionsFactory, TriCacheStore, type Type, TriCacheModule as default };
|