tricache 1.0.0 → 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-pJ-nFcVj.d.ts → cache-service-B108FzER.d.ts} +63 -3
- package/dist/cache-service-CWI4jkS7.d.cts +963 -0
- package/dist/{cache-service-26GCO3UU.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-VXFTFZ5N.js → chunk-VNRDL5RA.js} +117 -138
- package/dist/{chunk-7SZSQS55.js → chunk-WYF7NOAT.js} +1831 -759
- package/dist/cli.cjs +1757 -777
- 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 +1757 -773
- 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 +280 -153
- package/dist/edge/index.d.cts +127 -0
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +254 -147
- package/dist/hono/index.cjs +1805 -793
- 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-DuNvciyq.d.ts → hono-3rDMYVtY.d.ts} +23 -3
- package/dist/hono-C886ok3X.d.cts +391 -0
- package/dist/http/index.cjs +1946 -842
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +137 -57
- package/dist/index.cjs +2073 -937
- package/dist/index.d.cts +1006 -0
- package/dist/index.d.ts +40 -8
- package/dist/index.js +8 -8
- package/dist/murmur3-CMGw9PbV.d.cts +98 -0
- package/dist/nestjs/index.cjs +1849 -806
- 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 +1913 -887
- package/dist/next/index.d.cts +232 -0
- package/dist/next/index.d.ts +33 -11
- package/dist/next/index.js +174 -107
- 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-5HXqBfAf.d.ts → types-BA4pz1A0.d.cts} +26 -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 +123 -25
- package/src/cache-service.ts +1238 -659
- 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 +202 -129
- 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 +110 -26
- package/src/http/fastify.ts +38 -28
- 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 +132 -57
- package/src/next/index.ts +1 -0
- package/src/next/isr-handler.ts +1 -4
- package/src/next/types.ts +21 -0
- package/src/prisma/index.ts +12 -1
- package/src/smart-memory-cache.ts +65 -27
- package/src/types.ts +27 -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
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { C as CacheOptions, f as CachePriority } from '../types-BA4pz1A0.cjs';
|
|
2
|
+
import { C as CacheService } from '../cache-service-CWI4jkS7.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 (0 = indefinite / default engine TTL)
|
|
142
|
+
*/
|
|
143
|
+
set<T>(key: string, value: T, ttl?: number): Promise<T>;
|
|
144
|
+
/**
|
|
145
|
+
* Remove an item from the cache.
|
|
146
|
+
*/
|
|
147
|
+
del(key: string): Promise<boolean>;
|
|
148
|
+
/**
|
|
149
|
+
* Clear the entire cache namespace.
|
|
150
|
+
*/
|
|
151
|
+
reset(): Promise<boolean>;
|
|
152
|
+
/**
|
|
153
|
+
* Batch get multiple items from the cache. Accepts cache-manager 7's key array
|
|
154
|
+
* and the legacy cache-store variadic form.
|
|
155
|
+
*/
|
|
156
|
+
mget<T>(keys: string[]): Promise<(T | undefined)[]>;
|
|
157
|
+
mget<T>(...keys: string[]): Promise<(T | undefined)[]>;
|
|
158
|
+
/**
|
|
159
|
+
* Batch set multiple entries with per-entry millisecond TTL.
|
|
160
|
+
*/
|
|
161
|
+
mset(entries: Array<{
|
|
162
|
+
key: string;
|
|
163
|
+
value: unknown;
|
|
164
|
+
ttl?: number;
|
|
165
|
+
}>): Promise<Array<{
|
|
166
|
+
key: string;
|
|
167
|
+
value: unknown;
|
|
168
|
+
ttl?: number;
|
|
169
|
+
}>>;
|
|
170
|
+
/**
|
|
171
|
+
* Batch delete multiple keys.
|
|
172
|
+
*/
|
|
173
|
+
mdel(keys: string[]): Promise<boolean>;
|
|
174
|
+
mdel(...keys: string[]): Promise<boolean>;
|
|
175
|
+
/**
|
|
176
|
+
* Scan keys currently resident in the cache.
|
|
177
|
+
*/
|
|
178
|
+
keys(pattern?: string): Promise<string[]>;
|
|
179
|
+
/**
|
|
180
|
+
* Get remaining TTL for a key in milliseconds.
|
|
181
|
+
*/
|
|
182
|
+
ttl(key: string): Promise<number | undefined>;
|
|
183
|
+
wrap<T>(key: string, fetch: () => T | Promise<T>, ttl?: number, refreshThreshold?: number): Promise<T>;
|
|
184
|
+
cacheId(): string;
|
|
185
|
+
get stores(): unknown[];
|
|
186
|
+
clear(): Promise<boolean>;
|
|
187
|
+
disconnect(): Promise<undefined>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Relative-millisecond storage adapter for Keyv 5 / cache-manager 7.
|
|
192
|
+
* Wrap it in Keyv before passing it to Nest's CacheModule. Unlike TriCacheStore,
|
|
193
|
+
* this is a storage adapter, not the injected cache-manager facade.
|
|
194
|
+
* The supplied engine remains caller-owned when Keyv disconnects.
|
|
195
|
+
*/
|
|
196
|
+
declare class TriCacheKeyvAdapter extends EventEmitter {
|
|
197
|
+
readonly cache: CacheService;
|
|
198
|
+
private _namespace?;
|
|
199
|
+
constructor(cache: CacheService);
|
|
200
|
+
get namespace(): string | undefined;
|
|
201
|
+
set namespace(value: string | undefined);
|
|
202
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
203
|
+
set(key: string, value: unknown, ttl?: number): Promise<boolean>;
|
|
204
|
+
delete(key: string): Promise<boolean>;
|
|
205
|
+
clear(): Promise<void>;
|
|
206
|
+
has(key: string): Promise<boolean>;
|
|
207
|
+
getMany<T = unknown>(keys: string[]): Promise<(T | undefined)[]>;
|
|
208
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
209
|
+
setMany(entries: Array<{
|
|
210
|
+
key: string;
|
|
211
|
+
value: unknown;
|
|
212
|
+
ttl?: number;
|
|
213
|
+
}>): Promise<boolean[]>;
|
|
214
|
+
hasMany(keys: string[]): Promise<boolean[]>;
|
|
215
|
+
disconnect(): Promise<void>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface CacheableOptions {
|
|
219
|
+
/**
|
|
220
|
+
* Static key string or dynamic key generator function.
|
|
221
|
+
* Example: (id: string) => `user:${id}`
|
|
222
|
+
*/
|
|
223
|
+
key?: string | ((...args: any[]) => string);
|
|
224
|
+
/** TTL in seconds (or milliseconds if specified / detected). Default: 300 s. */
|
|
225
|
+
ttl?: number;
|
|
226
|
+
/** Explicit time unit for the ttl option. Default: 'seconds'. */
|
|
227
|
+
ttlUnit?: 'seconds' | 'milliseconds';
|
|
228
|
+
/** Stale-While-Revalidate grace period in seconds. */
|
|
229
|
+
swr?: number;
|
|
230
|
+
/** Semantic tags for invalidation. */
|
|
231
|
+
tags?: string[] | ((...args: any[]) => string[]);
|
|
232
|
+
/** Dependency cascade patterns. */
|
|
233
|
+
dependsOn?: string[] | ((...args: any[]) => string[]);
|
|
234
|
+
/** Cache eviction priority. */
|
|
235
|
+
priority?: CachePriority;
|
|
236
|
+
/** 0–1 fraction of TTL elapsed for background recompute. */
|
|
237
|
+
refreshAhead?: number;
|
|
238
|
+
/** XFetch probabilistic early expiration factor (0.5–2.0). */
|
|
239
|
+
xfetchBeta?: number;
|
|
240
|
+
/** Condition predicate to determine whether caching should occur. */
|
|
241
|
+
condition?: (...args: any[]) => boolean;
|
|
242
|
+
}
|
|
243
|
+
interface CacheEvictOptions {
|
|
244
|
+
/** Key or pattern to delete. */
|
|
245
|
+
key?: string | ((...args: any[]) => string);
|
|
246
|
+
/** Tags to invalidate. */
|
|
247
|
+
tags?: string[] | ((...args: any[]) => string[]);
|
|
248
|
+
/** Invalidate before method execution (default: false = after successful execution). */
|
|
249
|
+
beforeInvocation?: boolean;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Declarative method decorator that caches the return value of an async method.
|
|
253
|
+
*
|
|
254
|
+
* Automatically intercepts calls, checks TriCache (L1 -> L1.5 -> L2), and falls
|
|
255
|
+
* back to executing the decorated method on cache miss with thundering-herd protection.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* @Injectable()
|
|
260
|
+
* export class UserService {
|
|
261
|
+
* @Cacheable({ key: (id) => `user:${id}`, ttl: 300, tags: ['users'] })
|
|
262
|
+
* async findById(id: string) {
|
|
263
|
+
* return this.db.find(id);
|
|
264
|
+
* }
|
|
265
|
+
* }
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
declare function Cacheable(options?: CacheableOptions): MethodDecorator;
|
|
269
|
+
/**
|
|
270
|
+
* Declarative method decorator that invalidates cache keys or tags upon method execution.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* @Injectable()
|
|
275
|
+
* export class UserService {
|
|
276
|
+
* @CacheEvict({ tags: ['users'] })
|
|
277
|
+
* async update(id: string, dto: UpdateUserDto) {
|
|
278
|
+
* return this.db.update(id, dto);
|
|
279
|
+
* }
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
declare function CacheEvict(options?: CacheEvictOptions): MethodDecorator;
|
|
284
|
+
|
|
285
|
+
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-BA4pz1A0.js';
|
|
2
|
+
import { C as CacheService } from '../cache-service-B108FzER.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,46 @@ 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
141
|
* @param ttl - TTL in milliseconds (0 = indefinite / default engine TTL)
|
|
109
142
|
*/
|
|
110
|
-
set<T>(key: string, value: T, ttl?: number): Promise<
|
|
143
|
+
set<T>(key: string, value: T, ttl?: number): Promise<T>;
|
|
111
144
|
/**
|
|
112
145
|
* Remove an item from the cache.
|
|
113
146
|
*/
|
|
114
|
-
del(key: string): Promise<
|
|
147
|
+
del(key: string): Promise<boolean>;
|
|
115
148
|
/**
|
|
116
149
|
* Clear the entire cache namespace.
|
|
117
150
|
*/
|
|
118
|
-
reset(): Promise<
|
|
151
|
+
reset(): Promise<boolean>;
|
|
119
152
|
/**
|
|
120
|
-
* Batch get multiple items from the cache.
|
|
153
|
+
* Batch get multiple items from the cache. Accepts cache-manager 7's key array
|
|
154
|
+
* and the legacy cache-store variadic form.
|
|
121
155
|
*/
|
|
156
|
+
mget<T>(keys: string[]): Promise<(T | undefined)[]>;
|
|
122
157
|
mget<T>(...keys: string[]): Promise<(T | undefined)[]>;
|
|
123
158
|
/**
|
|
124
159
|
* Batch set multiple entries with per-entry millisecond TTL.
|
|
@@ -127,11 +162,16 @@ declare class TriCacheStore implements NestCacheStore {
|
|
|
127
162
|
key: string;
|
|
128
163
|
value: unknown;
|
|
129
164
|
ttl?: number;
|
|
130
|
-
}>): Promise<
|
|
165
|
+
}>): Promise<Array<{
|
|
166
|
+
key: string;
|
|
167
|
+
value: unknown;
|
|
168
|
+
ttl?: number;
|
|
169
|
+
}>>;
|
|
131
170
|
/**
|
|
132
171
|
* Batch delete multiple keys.
|
|
133
172
|
*/
|
|
134
|
-
mdel(
|
|
173
|
+
mdel(keys: string[]): Promise<boolean>;
|
|
174
|
+
mdel(...keys: string[]): Promise<boolean>;
|
|
135
175
|
/**
|
|
136
176
|
* Scan keys currently resident in the cache.
|
|
137
177
|
*/
|
|
@@ -140,6 +180,39 @@ declare class TriCacheStore implements NestCacheStore {
|
|
|
140
180
|
* Get remaining TTL for a key in milliseconds.
|
|
141
181
|
*/
|
|
142
182
|
ttl(key: string): Promise<number | undefined>;
|
|
183
|
+
wrap<T>(key: string, fetch: () => T | Promise<T>, ttl?: number, refreshThreshold?: number): Promise<T>;
|
|
184
|
+
cacheId(): string;
|
|
185
|
+
get stores(): unknown[];
|
|
186
|
+
clear(): Promise<boolean>;
|
|
187
|
+
disconnect(): Promise<undefined>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Relative-millisecond storage adapter for Keyv 5 / cache-manager 7.
|
|
192
|
+
* Wrap it in Keyv before passing it to Nest's CacheModule. Unlike TriCacheStore,
|
|
193
|
+
* this is a storage adapter, not the injected cache-manager facade.
|
|
194
|
+
* The supplied engine remains caller-owned when Keyv disconnects.
|
|
195
|
+
*/
|
|
196
|
+
declare class TriCacheKeyvAdapter extends EventEmitter {
|
|
197
|
+
readonly cache: CacheService;
|
|
198
|
+
private _namespace?;
|
|
199
|
+
constructor(cache: CacheService);
|
|
200
|
+
get namespace(): string | undefined;
|
|
201
|
+
set namespace(value: string | undefined);
|
|
202
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
203
|
+
set(key: string, value: unknown, ttl?: number): Promise<boolean>;
|
|
204
|
+
delete(key: string): Promise<boolean>;
|
|
205
|
+
clear(): Promise<void>;
|
|
206
|
+
has(key: string): Promise<boolean>;
|
|
207
|
+
getMany<T = unknown>(keys: string[]): Promise<(T | undefined)[]>;
|
|
208
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
209
|
+
setMany(entries: Array<{
|
|
210
|
+
key: string;
|
|
211
|
+
value: unknown;
|
|
212
|
+
ttl?: number;
|
|
213
|
+
}>): Promise<boolean[]>;
|
|
214
|
+
hasMany(keys: string[]): Promise<boolean[]>;
|
|
215
|
+
disconnect(): Promise<void>;
|
|
143
216
|
}
|
|
144
217
|
|
|
145
218
|
interface CacheableOptions {
|
|
@@ -209,4 +282,4 @@ declare function Cacheable(options?: CacheableOptions): MethodDecorator;
|
|
|
209
282
|
*/
|
|
210
283
|
declare function CacheEvict(options?: CacheEvictOptions): MethodDecorator;
|
|
211
284
|
|
|
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 };
|
|
285
|
+
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 };
|