dialcache 0.1.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 +21 -0
- package/README.md +357 -0
- package/dist/chunk-2TPHNNE7.js +164 -0
- package/dist/chunk-BF6XTPTS.js +32 -0
- package/dist/chunk-S5VCTJID.js +18 -0
- package/dist/config-B7bGp-Xj.d.cts +205 -0
- package/dist/config-B7bGp-Xj.d.ts +205 -0
- package/dist/index.cjs +1011 -0
- package/dist/index.d.cts +93 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +956 -0
- package/dist/node-redis.cjs +329 -0
- package/dist/node-redis.d.cts +52 -0
- package/dist/node-redis.d.ts +52 -0
- package/dist/node-redis.js +127 -0
- package/dist/redis-protocol.cjs +197 -0
- package/dist/redis-protocol.d.cts +10 -0
- package/dist/redis-protocol.d.ts +10 -0
- package/dist/redis-protocol.js +20 -0
- package/dist/valkey-glide.cjs +299 -0
- package/dist/valkey-glide.d.cts +12 -0
- package/dist/valkey-glide.d.ts +12 -0
- package/dist/valkey-glide.js +104 -0
- package/package.json +115 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Registry } from 'prom-client';
|
|
2
|
+
|
|
3
|
+
interface Serializer<T = unknown> {
|
|
4
|
+
dump(value: T): Awaitable<string | Buffer>;
|
|
5
|
+
load(value: string | Buffer): Awaitable<T>;
|
|
6
|
+
}
|
|
7
|
+
declare class JsonSerializer<T = unknown> implements Serializer<T> {
|
|
8
|
+
dump(value: T): Promise<string>;
|
|
9
|
+
load(value: string | Buffer): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface DialCacheKeyInit {
|
|
13
|
+
readonly keyType: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly useCase: string;
|
|
16
|
+
readonly args?: ReadonlyArray<readonly [string, string]>;
|
|
17
|
+
readonly urnPrefix?: string;
|
|
18
|
+
readonly defaultConfig?: DialCacheKeyConfig | null;
|
|
19
|
+
readonly serializer?: Serializer<unknown> | null;
|
|
20
|
+
readonly trackForInvalidation?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare class DialCacheKey {
|
|
23
|
+
readonly keyType: string;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly useCase: string;
|
|
26
|
+
readonly args: ReadonlyArray<readonly [string, string]>;
|
|
27
|
+
readonly urnPrefix: string;
|
|
28
|
+
readonly prefix: string;
|
|
29
|
+
readonly urn: string;
|
|
30
|
+
readonly defaultConfig: DialCacheKeyConfig | null;
|
|
31
|
+
readonly serializer: Serializer<unknown> | null;
|
|
32
|
+
readonly trackForInvalidation: boolean;
|
|
33
|
+
constructor(init: DialCacheKeyInit);
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
36
|
+
declare function normalizeArgs(args: Record<string, string | number | boolean | bigint | null | undefined>): Array<[string, string]>;
|
|
37
|
+
declare function invalidationPrefix(urnPrefix: string, keyType: string, id: string): string;
|
|
38
|
+
declare function redisClusterHashTag(value: string): string;
|
|
39
|
+
|
|
40
|
+
declare const NO_CACHE_LAYER = "noop";
|
|
41
|
+
type NoCacheLayer = typeof NO_CACHE_LAYER;
|
|
42
|
+
type MetricLayer = CacheLayer | NoCacheLayer;
|
|
43
|
+
type DisabledReason = "context" | "missing_config" | "invalid_ttl" | "ramped_down" | "config_error";
|
|
44
|
+
interface CacheMetricLabels {
|
|
45
|
+
readonly useCase: string;
|
|
46
|
+
readonly keyType: string;
|
|
47
|
+
readonly layer: MetricLayer;
|
|
48
|
+
}
|
|
49
|
+
interface DisabledMetricLabels extends CacheMetricLabels {
|
|
50
|
+
readonly reason: DisabledReason;
|
|
51
|
+
}
|
|
52
|
+
interface ErrorMetricLabels extends CacheMetricLabels {
|
|
53
|
+
readonly error: string;
|
|
54
|
+
readonly inFallback: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface SerializationMetricLabels extends CacheMetricLabels {
|
|
57
|
+
readonly operation: "dump" | "load";
|
|
58
|
+
}
|
|
59
|
+
interface InvalidationMetricLabels {
|
|
60
|
+
readonly keyType: string;
|
|
61
|
+
readonly layer: CacheLayer;
|
|
62
|
+
}
|
|
63
|
+
interface CoalescedMetricLabels {
|
|
64
|
+
readonly useCase: string;
|
|
65
|
+
readonly keyType: string;
|
|
66
|
+
}
|
|
67
|
+
interface DialCacheMetricsAdapter {
|
|
68
|
+
request(labels: CacheMetricLabels): void;
|
|
69
|
+
miss(labels: CacheMetricLabels): void;
|
|
70
|
+
disabled(labels: DisabledMetricLabels): void;
|
|
71
|
+
error(labels: ErrorMetricLabels): void;
|
|
72
|
+
invalidation(labels: InvalidationMetricLabels): void;
|
|
73
|
+
coalesced?(labels: CoalescedMetricLabels): void;
|
|
74
|
+
observeGet(labels: CacheMetricLabels, seconds: number): void;
|
|
75
|
+
observeFallback(labels: CacheMetricLabels, seconds: number): void;
|
|
76
|
+
observeSerialization(labels: SerializationMetricLabels, seconds: number): void;
|
|
77
|
+
observeSize(labels: CacheMetricLabels, bytes: number): void;
|
|
78
|
+
}
|
|
79
|
+
interface PrometheusMetricsOptions {
|
|
80
|
+
readonly prefix?: string;
|
|
81
|
+
readonly registry?: Registry;
|
|
82
|
+
}
|
|
83
|
+
declare class PrometheusDialCacheMetrics implements DialCacheMetricsAdapter {
|
|
84
|
+
private readonly requestCounter;
|
|
85
|
+
private readonly missCounter;
|
|
86
|
+
private readonly disabledCounter;
|
|
87
|
+
private readonly errorCounter;
|
|
88
|
+
private readonly invalidationCounter;
|
|
89
|
+
private readonly coalescedCounter;
|
|
90
|
+
private readonly getTimer;
|
|
91
|
+
private readonly fallbackTimer;
|
|
92
|
+
private readonly serializationTimer;
|
|
93
|
+
private readonly sizeHistogram;
|
|
94
|
+
constructor(options?: PrometheusMetricsOptions);
|
|
95
|
+
request(labels: CacheMetricLabels): void;
|
|
96
|
+
miss(labels: CacheMetricLabels): void;
|
|
97
|
+
disabled(labels: DisabledMetricLabels): void;
|
|
98
|
+
error(labels: ErrorMetricLabels): void;
|
|
99
|
+
invalidation(labels: InvalidationMetricLabels): void;
|
|
100
|
+
coalesced(labels: CoalescedMetricLabels): void;
|
|
101
|
+
observeGet(labels: CacheMetricLabels, seconds: number): void;
|
|
102
|
+
observeFallback(labels: CacheMetricLabels, seconds: number): void;
|
|
103
|
+
observeSerialization(labels: SerializationMetricLabels, seconds: number): void;
|
|
104
|
+
observeSize(labels: CacheMetricLabels, bytes: number): void;
|
|
105
|
+
}
|
|
106
|
+
declare function createPrometheusDialCacheMetrics(options?: PrometheusMetricsOptions): DialCacheMetricsAdapter;
|
|
107
|
+
|
|
108
|
+
declare class DialCacheRedisPayloadError extends Error {
|
|
109
|
+
constructor(message: string);
|
|
110
|
+
}
|
|
111
|
+
declare class DialCacheRedisPayloadEncodingError extends Error {
|
|
112
|
+
constructor(message: string);
|
|
113
|
+
}
|
|
114
|
+
/** Serialized cache data, independent of any Redis client or wire framing. */
|
|
115
|
+
type RedisCachePayload = string | Buffer;
|
|
116
|
+
interface RedisValueRequest {
|
|
117
|
+
readonly valueKey: string;
|
|
118
|
+
}
|
|
119
|
+
interface TrackedRedisValueRequest extends RedisValueRequest {
|
|
120
|
+
readonly watermarkKey: string;
|
|
121
|
+
}
|
|
122
|
+
interface UntrackedRedisValueRequest extends RedisValueRequest {
|
|
123
|
+
readonly watermarkKey?: never;
|
|
124
|
+
}
|
|
125
|
+
type RedisReadRequest = TrackedRedisValueRequest | UntrackedRedisValueRequest;
|
|
126
|
+
interface RedisWriteBase extends RedisValueRequest {
|
|
127
|
+
readonly cacheTtlMs: number;
|
|
128
|
+
readonly value: RedisCachePayload;
|
|
129
|
+
}
|
|
130
|
+
interface TrackedRedisWriteRequest extends RedisWriteBase, TrackedRedisValueRequest {
|
|
131
|
+
readonly watermarkTtlFloorMs: number;
|
|
132
|
+
}
|
|
133
|
+
interface UntrackedRedisWriteRequest extends RedisWriteBase, UntrackedRedisValueRequest {
|
|
134
|
+
readonly watermarkTtlFloorMs?: never;
|
|
135
|
+
}
|
|
136
|
+
type RedisWriteRequest = TrackedRedisWriteRequest | UntrackedRedisWriteRequest;
|
|
137
|
+
interface RedisInvalidationRequest {
|
|
138
|
+
readonly watermarkKey: string;
|
|
139
|
+
readonly futureBufferMs: number;
|
|
140
|
+
readonly watermarkTtlFloorMs: number;
|
|
141
|
+
}
|
|
142
|
+
interface DialCacheRedisClient {
|
|
143
|
+
/** Atomically read and validate a value against its watermark when tracked. */
|
|
144
|
+
read(request: RedisReadRequest): Awaitable<RedisCachePayload | null>;
|
|
145
|
+
/** Atomically write using server time. False means invalidation blocked the write. */
|
|
146
|
+
write(request: RedisWriteRequest): Awaitable<boolean>;
|
|
147
|
+
/** Advance the watermark monotonically after the source mutation commits. */
|
|
148
|
+
invalidate(request: RedisInvalidationRequest): Awaitable<void>;
|
|
149
|
+
/** Remove cached values from every backing shard. */
|
|
150
|
+
flushAll(): Awaitable<void>;
|
|
151
|
+
}
|
|
152
|
+
type RedisClientFactory = () => Awaitable<DialCacheRedisClient>;
|
|
153
|
+
|
|
154
|
+
interface RedisConfig {
|
|
155
|
+
readonly client?: DialCacheRedisClient;
|
|
156
|
+
readonly createClient?: RedisClientFactory;
|
|
157
|
+
readonly keyPrefix?: string;
|
|
158
|
+
readonly serializer?: Serializer<unknown>;
|
|
159
|
+
readonly watermarkTtlSec?: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
declare enum CacheLayer {
|
|
163
|
+
LOCAL = "local",
|
|
164
|
+
REMOTE = "remote"
|
|
165
|
+
}
|
|
166
|
+
type Awaitable<T> = T | Promise<T>;
|
|
167
|
+
type LayerConfig = Partial<Record<CacheLayer, number>>;
|
|
168
|
+
interface CacheRampSample {
|
|
169
|
+
readonly key: DialCacheKey;
|
|
170
|
+
readonly layer: CacheLayer;
|
|
171
|
+
readonly ramp: number;
|
|
172
|
+
}
|
|
173
|
+
type CacheRampSampler = (sample: CacheRampSample) => Awaitable<number>;
|
|
174
|
+
declare const deterministicRampSampler: CacheRampSampler;
|
|
175
|
+
declare const randomRampSampler: CacheRampSampler;
|
|
176
|
+
declare const DEFAULT_WATERMARK_TTL_SEC: number;
|
|
177
|
+
declare class DialCacheKeyConfig {
|
|
178
|
+
readonly ttlSec: LayerConfig;
|
|
179
|
+
readonly ramp: LayerConfig;
|
|
180
|
+
constructor(config: {
|
|
181
|
+
ttlSec: LayerConfig;
|
|
182
|
+
ramp: LayerConfig;
|
|
183
|
+
});
|
|
184
|
+
static enabled(ttlSec: number): DialCacheKeyConfig;
|
|
185
|
+
}
|
|
186
|
+
type CacheConfigProvider = (key: DialCacheKey) => Awaitable<DialCacheKeyConfig | null>;
|
|
187
|
+
type Logger = Pick<Console, "debug" | "error" | "warn">;
|
|
188
|
+
interface DialCacheConfig {
|
|
189
|
+
readonly cacheConfigProvider?: CacheConfigProvider;
|
|
190
|
+
readonly urnPrefix?: string;
|
|
191
|
+
readonly logger?: Logger;
|
|
192
|
+
/**
|
|
193
|
+
* Maximum local entries across every use case in this DialCache instance.
|
|
194
|
+
* Must be a nonnegative safe integer.
|
|
195
|
+
* Zero disables local storage. Defaults to 10,000.
|
|
196
|
+
*/
|
|
197
|
+
readonly localMaxSize?: number;
|
|
198
|
+
readonly redis?: RedisConfig;
|
|
199
|
+
readonly rampSampler?: CacheRampSampler;
|
|
200
|
+
readonly metrics?: DialCacheMetricsAdapter | false;
|
|
201
|
+
readonly metricsPrefix?: string;
|
|
202
|
+
readonly metricsRegistry?: Registry;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { type Awaitable as A, normalizeArgs as B, type CacheConfigProvider as C, DialCacheKeyConfig as D, type ErrorMetricLabels as E, randomRampSampler as F, redisClusterHashTag as G, type InvalidationMetricLabels as I, JsonSerializer as J, type LayerConfig as L, type MetricLayer as M, PrometheusDialCacheMetrics as P, type RedisCachePayload as R, type Serializer as S, type DialCacheConfig as a, CacheLayer as b, type CacheMetricLabels as c, type CacheRampSample as d, type CacheRampSampler as e, type CoalescedMetricLabels as f, DEFAULT_WATERMARK_TTL_SEC as g, DialCacheKey as h, type DialCacheKeyInit as i, type DialCacheMetricsAdapter as j, type DialCacheRedisClient as k, DialCacheRedisPayloadEncodingError as l, DialCacheRedisPayloadError as m, type DisabledMetricLabels as n, type DisabledReason as o, type Logger as p, type PrometheusMetricsOptions as q, type RedisClientFactory as r, type RedisConfig as s, type RedisInvalidationRequest as t, type RedisReadRequest as u, type RedisWriteRequest as v, type SerializationMetricLabels as w, createPrometheusDialCacheMetrics as x, deterministicRampSampler as y, invalidationPrefix as z };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Registry } from 'prom-client';
|
|
2
|
+
|
|
3
|
+
interface Serializer<T = unknown> {
|
|
4
|
+
dump(value: T): Awaitable<string | Buffer>;
|
|
5
|
+
load(value: string | Buffer): Awaitable<T>;
|
|
6
|
+
}
|
|
7
|
+
declare class JsonSerializer<T = unknown> implements Serializer<T> {
|
|
8
|
+
dump(value: T): Promise<string>;
|
|
9
|
+
load(value: string | Buffer): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface DialCacheKeyInit {
|
|
13
|
+
readonly keyType: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly useCase: string;
|
|
16
|
+
readonly args?: ReadonlyArray<readonly [string, string]>;
|
|
17
|
+
readonly urnPrefix?: string;
|
|
18
|
+
readonly defaultConfig?: DialCacheKeyConfig | null;
|
|
19
|
+
readonly serializer?: Serializer<unknown> | null;
|
|
20
|
+
readonly trackForInvalidation?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare class DialCacheKey {
|
|
23
|
+
readonly keyType: string;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly useCase: string;
|
|
26
|
+
readonly args: ReadonlyArray<readonly [string, string]>;
|
|
27
|
+
readonly urnPrefix: string;
|
|
28
|
+
readonly prefix: string;
|
|
29
|
+
readonly urn: string;
|
|
30
|
+
readonly defaultConfig: DialCacheKeyConfig | null;
|
|
31
|
+
readonly serializer: Serializer<unknown> | null;
|
|
32
|
+
readonly trackForInvalidation: boolean;
|
|
33
|
+
constructor(init: DialCacheKeyInit);
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
36
|
+
declare function normalizeArgs(args: Record<string, string | number | boolean | bigint | null | undefined>): Array<[string, string]>;
|
|
37
|
+
declare function invalidationPrefix(urnPrefix: string, keyType: string, id: string): string;
|
|
38
|
+
declare function redisClusterHashTag(value: string): string;
|
|
39
|
+
|
|
40
|
+
declare const NO_CACHE_LAYER = "noop";
|
|
41
|
+
type NoCacheLayer = typeof NO_CACHE_LAYER;
|
|
42
|
+
type MetricLayer = CacheLayer | NoCacheLayer;
|
|
43
|
+
type DisabledReason = "context" | "missing_config" | "invalid_ttl" | "ramped_down" | "config_error";
|
|
44
|
+
interface CacheMetricLabels {
|
|
45
|
+
readonly useCase: string;
|
|
46
|
+
readonly keyType: string;
|
|
47
|
+
readonly layer: MetricLayer;
|
|
48
|
+
}
|
|
49
|
+
interface DisabledMetricLabels extends CacheMetricLabels {
|
|
50
|
+
readonly reason: DisabledReason;
|
|
51
|
+
}
|
|
52
|
+
interface ErrorMetricLabels extends CacheMetricLabels {
|
|
53
|
+
readonly error: string;
|
|
54
|
+
readonly inFallback: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface SerializationMetricLabels extends CacheMetricLabels {
|
|
57
|
+
readonly operation: "dump" | "load";
|
|
58
|
+
}
|
|
59
|
+
interface InvalidationMetricLabels {
|
|
60
|
+
readonly keyType: string;
|
|
61
|
+
readonly layer: CacheLayer;
|
|
62
|
+
}
|
|
63
|
+
interface CoalescedMetricLabels {
|
|
64
|
+
readonly useCase: string;
|
|
65
|
+
readonly keyType: string;
|
|
66
|
+
}
|
|
67
|
+
interface DialCacheMetricsAdapter {
|
|
68
|
+
request(labels: CacheMetricLabels): void;
|
|
69
|
+
miss(labels: CacheMetricLabels): void;
|
|
70
|
+
disabled(labels: DisabledMetricLabels): void;
|
|
71
|
+
error(labels: ErrorMetricLabels): void;
|
|
72
|
+
invalidation(labels: InvalidationMetricLabels): void;
|
|
73
|
+
coalesced?(labels: CoalescedMetricLabels): void;
|
|
74
|
+
observeGet(labels: CacheMetricLabels, seconds: number): void;
|
|
75
|
+
observeFallback(labels: CacheMetricLabels, seconds: number): void;
|
|
76
|
+
observeSerialization(labels: SerializationMetricLabels, seconds: number): void;
|
|
77
|
+
observeSize(labels: CacheMetricLabels, bytes: number): void;
|
|
78
|
+
}
|
|
79
|
+
interface PrometheusMetricsOptions {
|
|
80
|
+
readonly prefix?: string;
|
|
81
|
+
readonly registry?: Registry;
|
|
82
|
+
}
|
|
83
|
+
declare class PrometheusDialCacheMetrics implements DialCacheMetricsAdapter {
|
|
84
|
+
private readonly requestCounter;
|
|
85
|
+
private readonly missCounter;
|
|
86
|
+
private readonly disabledCounter;
|
|
87
|
+
private readonly errorCounter;
|
|
88
|
+
private readonly invalidationCounter;
|
|
89
|
+
private readonly coalescedCounter;
|
|
90
|
+
private readonly getTimer;
|
|
91
|
+
private readonly fallbackTimer;
|
|
92
|
+
private readonly serializationTimer;
|
|
93
|
+
private readonly sizeHistogram;
|
|
94
|
+
constructor(options?: PrometheusMetricsOptions);
|
|
95
|
+
request(labels: CacheMetricLabels): void;
|
|
96
|
+
miss(labels: CacheMetricLabels): void;
|
|
97
|
+
disabled(labels: DisabledMetricLabels): void;
|
|
98
|
+
error(labels: ErrorMetricLabels): void;
|
|
99
|
+
invalidation(labels: InvalidationMetricLabels): void;
|
|
100
|
+
coalesced(labels: CoalescedMetricLabels): void;
|
|
101
|
+
observeGet(labels: CacheMetricLabels, seconds: number): void;
|
|
102
|
+
observeFallback(labels: CacheMetricLabels, seconds: number): void;
|
|
103
|
+
observeSerialization(labels: SerializationMetricLabels, seconds: number): void;
|
|
104
|
+
observeSize(labels: CacheMetricLabels, bytes: number): void;
|
|
105
|
+
}
|
|
106
|
+
declare function createPrometheusDialCacheMetrics(options?: PrometheusMetricsOptions): DialCacheMetricsAdapter;
|
|
107
|
+
|
|
108
|
+
declare class DialCacheRedisPayloadError extends Error {
|
|
109
|
+
constructor(message: string);
|
|
110
|
+
}
|
|
111
|
+
declare class DialCacheRedisPayloadEncodingError extends Error {
|
|
112
|
+
constructor(message: string);
|
|
113
|
+
}
|
|
114
|
+
/** Serialized cache data, independent of any Redis client or wire framing. */
|
|
115
|
+
type RedisCachePayload = string | Buffer;
|
|
116
|
+
interface RedisValueRequest {
|
|
117
|
+
readonly valueKey: string;
|
|
118
|
+
}
|
|
119
|
+
interface TrackedRedisValueRequest extends RedisValueRequest {
|
|
120
|
+
readonly watermarkKey: string;
|
|
121
|
+
}
|
|
122
|
+
interface UntrackedRedisValueRequest extends RedisValueRequest {
|
|
123
|
+
readonly watermarkKey?: never;
|
|
124
|
+
}
|
|
125
|
+
type RedisReadRequest = TrackedRedisValueRequest | UntrackedRedisValueRequest;
|
|
126
|
+
interface RedisWriteBase extends RedisValueRequest {
|
|
127
|
+
readonly cacheTtlMs: number;
|
|
128
|
+
readonly value: RedisCachePayload;
|
|
129
|
+
}
|
|
130
|
+
interface TrackedRedisWriteRequest extends RedisWriteBase, TrackedRedisValueRequest {
|
|
131
|
+
readonly watermarkTtlFloorMs: number;
|
|
132
|
+
}
|
|
133
|
+
interface UntrackedRedisWriteRequest extends RedisWriteBase, UntrackedRedisValueRequest {
|
|
134
|
+
readonly watermarkTtlFloorMs?: never;
|
|
135
|
+
}
|
|
136
|
+
type RedisWriteRequest = TrackedRedisWriteRequest | UntrackedRedisWriteRequest;
|
|
137
|
+
interface RedisInvalidationRequest {
|
|
138
|
+
readonly watermarkKey: string;
|
|
139
|
+
readonly futureBufferMs: number;
|
|
140
|
+
readonly watermarkTtlFloorMs: number;
|
|
141
|
+
}
|
|
142
|
+
interface DialCacheRedisClient {
|
|
143
|
+
/** Atomically read and validate a value against its watermark when tracked. */
|
|
144
|
+
read(request: RedisReadRequest): Awaitable<RedisCachePayload | null>;
|
|
145
|
+
/** Atomically write using server time. False means invalidation blocked the write. */
|
|
146
|
+
write(request: RedisWriteRequest): Awaitable<boolean>;
|
|
147
|
+
/** Advance the watermark monotonically after the source mutation commits. */
|
|
148
|
+
invalidate(request: RedisInvalidationRequest): Awaitable<void>;
|
|
149
|
+
/** Remove cached values from every backing shard. */
|
|
150
|
+
flushAll(): Awaitable<void>;
|
|
151
|
+
}
|
|
152
|
+
type RedisClientFactory = () => Awaitable<DialCacheRedisClient>;
|
|
153
|
+
|
|
154
|
+
interface RedisConfig {
|
|
155
|
+
readonly client?: DialCacheRedisClient;
|
|
156
|
+
readonly createClient?: RedisClientFactory;
|
|
157
|
+
readonly keyPrefix?: string;
|
|
158
|
+
readonly serializer?: Serializer<unknown>;
|
|
159
|
+
readonly watermarkTtlSec?: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
declare enum CacheLayer {
|
|
163
|
+
LOCAL = "local",
|
|
164
|
+
REMOTE = "remote"
|
|
165
|
+
}
|
|
166
|
+
type Awaitable<T> = T | Promise<T>;
|
|
167
|
+
type LayerConfig = Partial<Record<CacheLayer, number>>;
|
|
168
|
+
interface CacheRampSample {
|
|
169
|
+
readonly key: DialCacheKey;
|
|
170
|
+
readonly layer: CacheLayer;
|
|
171
|
+
readonly ramp: number;
|
|
172
|
+
}
|
|
173
|
+
type CacheRampSampler = (sample: CacheRampSample) => Awaitable<number>;
|
|
174
|
+
declare const deterministicRampSampler: CacheRampSampler;
|
|
175
|
+
declare const randomRampSampler: CacheRampSampler;
|
|
176
|
+
declare const DEFAULT_WATERMARK_TTL_SEC: number;
|
|
177
|
+
declare class DialCacheKeyConfig {
|
|
178
|
+
readonly ttlSec: LayerConfig;
|
|
179
|
+
readonly ramp: LayerConfig;
|
|
180
|
+
constructor(config: {
|
|
181
|
+
ttlSec: LayerConfig;
|
|
182
|
+
ramp: LayerConfig;
|
|
183
|
+
});
|
|
184
|
+
static enabled(ttlSec: number): DialCacheKeyConfig;
|
|
185
|
+
}
|
|
186
|
+
type CacheConfigProvider = (key: DialCacheKey) => Awaitable<DialCacheKeyConfig | null>;
|
|
187
|
+
type Logger = Pick<Console, "debug" | "error" | "warn">;
|
|
188
|
+
interface DialCacheConfig {
|
|
189
|
+
readonly cacheConfigProvider?: CacheConfigProvider;
|
|
190
|
+
readonly urnPrefix?: string;
|
|
191
|
+
readonly logger?: Logger;
|
|
192
|
+
/**
|
|
193
|
+
* Maximum local entries across every use case in this DialCache instance.
|
|
194
|
+
* Must be a nonnegative safe integer.
|
|
195
|
+
* Zero disables local storage. Defaults to 10,000.
|
|
196
|
+
*/
|
|
197
|
+
readonly localMaxSize?: number;
|
|
198
|
+
readonly redis?: RedisConfig;
|
|
199
|
+
readonly rampSampler?: CacheRampSampler;
|
|
200
|
+
readonly metrics?: DialCacheMetricsAdapter | false;
|
|
201
|
+
readonly metricsPrefix?: string;
|
|
202
|
+
readonly metricsRegistry?: Registry;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { type Awaitable as A, normalizeArgs as B, type CacheConfigProvider as C, DialCacheKeyConfig as D, type ErrorMetricLabels as E, randomRampSampler as F, redisClusterHashTag as G, type InvalidationMetricLabels as I, JsonSerializer as J, type LayerConfig as L, type MetricLayer as M, PrometheusDialCacheMetrics as P, type RedisCachePayload as R, type Serializer as S, type DialCacheConfig as a, CacheLayer as b, type CacheMetricLabels as c, type CacheRampSample as d, type CacheRampSampler as e, type CoalescedMetricLabels as f, DEFAULT_WATERMARK_TTL_SEC as g, DialCacheKey as h, type DialCacheKeyInit as i, type DialCacheMetricsAdapter as j, type DialCacheRedisClient as k, DialCacheRedisPayloadEncodingError as l, DialCacheRedisPayloadError as m, type DisabledMetricLabels as n, type DisabledReason as o, type Logger as p, type PrometheusMetricsOptions as q, type RedisClientFactory as r, type RedisConfig as s, type RedisInvalidationRequest as t, type RedisReadRequest as u, type RedisWriteRequest as v, type SerializationMetricLabels as w, createPrometheusDialCacheMetrics as x, deterministicRampSampler as y, invalidationPrefix as z };
|