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
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { D as DialCacheKeyConfig, S as Serializer, a as DialCacheConfig, A as Awaitable } from './config-B7bGp-Xj.cjs';
|
|
2
|
+
export { C as CacheConfigProvider, b as CacheLayer, c as CacheMetricLabels, d as CacheRampSample, e as CacheRampSampler, f as CoalescedMetricLabels, g as DEFAULT_WATERMARK_TTL_SEC, h as DialCacheKey, i as DialCacheKeyInit, j as DialCacheMetricsAdapter, k as DialCacheRedisClient, l as DialCacheRedisPayloadEncodingError, m as DialCacheRedisPayloadError, n as DisabledMetricLabels, o as DisabledReason, E as ErrorMetricLabels, I as InvalidationMetricLabels, J as JsonSerializer, L as LayerConfig, p as Logger, M as MetricLayer, P as PrometheusDialCacheMetrics, q as PrometheusMetricsOptions, R as RedisCachePayload, r as RedisClientFactory, s as RedisConfig, t as RedisInvalidationRequest, u as RedisReadRequest, v as RedisWriteRequest, w as SerializationMetricLabels, x as createPrometheusDialCacheMetrics, y as deterministicRampSampler, z as invalidationPrefix, B as normalizeArgs, F as randomRampSampler, G as redisClusterHashTag } from './config-B7bGp-Xj.cjs';
|
|
3
|
+
import 'prom-client';
|
|
4
|
+
|
|
5
|
+
declare class DialCacheContext {
|
|
6
|
+
private readonly storage;
|
|
7
|
+
isEnabled(): boolean;
|
|
8
|
+
enable<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
9
|
+
disable<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
10
|
+
private run;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class DialCacheError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
declare class UseCaseIsAlreadyRegisteredError extends DialCacheError {
|
|
17
|
+
constructor(useCase: string);
|
|
18
|
+
}
|
|
19
|
+
declare class UseCaseNameIsReservedError extends DialCacheError {
|
|
20
|
+
constructor(useCase: string);
|
|
21
|
+
}
|
|
22
|
+
declare class MissingKeyConfigError extends DialCacheError {
|
|
23
|
+
constructor(useCase: string);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type CacheKeyArgs = Record<string, string | number | boolean | bigint | null | undefined>;
|
|
27
|
+
type Id = string | number | bigint;
|
|
28
|
+
/** A cache-key spec: a bare id, or an id plus extra (secondary) key dimensions. */
|
|
29
|
+
type CacheKeySpec = Id | {
|
|
30
|
+
readonly id: Id;
|
|
31
|
+
readonly args?: CacheKeyArgs;
|
|
32
|
+
};
|
|
33
|
+
type AnyFn = (...args: never[]) => unknown;
|
|
34
|
+
/** The cached value type, derived from the wrapped function's return. */
|
|
35
|
+
type CachedValue<Fn extends AnyFn> = Awaited<ReturnType<Fn>>;
|
|
36
|
+
type CacheKeySelector<Fn extends AnyFn> = (...args: Parameters<Fn>) => CacheKeySpec;
|
|
37
|
+
interface CachedOptions<Fn extends AnyFn> {
|
|
38
|
+
readonly keyType: string;
|
|
39
|
+
readonly useCase: string;
|
|
40
|
+
readonly defaultConfig?: DialCacheKeyConfig | null;
|
|
41
|
+
readonly serializer?: Serializer<CachedValue<Fn>> | null;
|
|
42
|
+
readonly trackForInvalidation?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Select every input dimension that can affect the returned value. Concurrent
|
|
45
|
+
* enabled calls with the same cache key may share one in-flight execution.
|
|
46
|
+
*/
|
|
47
|
+
readonly cacheKey: CacheKeySelector<Fn>;
|
|
48
|
+
}
|
|
49
|
+
type CachedFn<Fn extends AnyFn> = (...args: Parameters<Fn>) => Promise<CachedValue<Fn>>;
|
|
50
|
+
declare class DialCache {
|
|
51
|
+
private readonly context;
|
|
52
|
+
private readonly localCache;
|
|
53
|
+
private readonly useCases;
|
|
54
|
+
private readonly configProvider;
|
|
55
|
+
private readonly urnPrefix;
|
|
56
|
+
private readonly logger;
|
|
57
|
+
private readonly rampSampler;
|
|
58
|
+
private readonly redisCache;
|
|
59
|
+
private readonly metrics;
|
|
60
|
+
private readonly inFlight;
|
|
61
|
+
constructor(config?: DialCacheConfig);
|
|
62
|
+
enable<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
63
|
+
disable<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
64
|
+
withEnabled<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
65
|
+
withDisabled<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
66
|
+
isEnabled(): boolean;
|
|
67
|
+
cached<Fn extends AnyFn>(fn: Fn, options: CachedOptions<Fn>): CachedFn<Fn>;
|
|
68
|
+
/**
|
|
69
|
+
* Writes a remote invalidation watermark for Redis-tracked entries.
|
|
70
|
+
*
|
|
71
|
+
* This does not synchronously evict local cache hits or untracked Redis values.
|
|
72
|
+
*
|
|
73
|
+
* @param futureBufferMs Nonnegative safe integer covering source lag and stale fallback work through the Redis write.
|
|
74
|
+
*/
|
|
75
|
+
invalidateRemote(keyType: string, id: Id, futureBufferMs?: number): Promise<void>;
|
|
76
|
+
flushAll(): Promise<void>;
|
|
77
|
+
private getThroughLocalOnly;
|
|
78
|
+
private getThroughRedisChain;
|
|
79
|
+
private getThroughRemoteAfterLocal;
|
|
80
|
+
private finishRedisChain;
|
|
81
|
+
private readLocal;
|
|
82
|
+
private resolveRemoteLayerConfig;
|
|
83
|
+
private readRemote;
|
|
84
|
+
private readRemoteWithResolvedConfig;
|
|
85
|
+
private putLocalFailOpen;
|
|
86
|
+
private callFallback;
|
|
87
|
+
private recordError;
|
|
88
|
+
private registerUseCase;
|
|
89
|
+
private buildKey;
|
|
90
|
+
private singleFlight;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type CacheKeySpec, type CachedFn, type CachedOptions, type CachedValue, DialCache, DialCacheConfig, DialCacheContext, DialCacheError, DialCacheKeyConfig, MissingKeyConfigError, Serializer, UseCaseIsAlreadyRegisteredError, UseCaseNameIsReservedError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { D as DialCacheKeyConfig, S as Serializer, a as DialCacheConfig, A as Awaitable } from './config-B7bGp-Xj.js';
|
|
2
|
+
export { C as CacheConfigProvider, b as CacheLayer, c as CacheMetricLabels, d as CacheRampSample, e as CacheRampSampler, f as CoalescedMetricLabels, g as DEFAULT_WATERMARK_TTL_SEC, h as DialCacheKey, i as DialCacheKeyInit, j as DialCacheMetricsAdapter, k as DialCacheRedisClient, l as DialCacheRedisPayloadEncodingError, m as DialCacheRedisPayloadError, n as DisabledMetricLabels, o as DisabledReason, E as ErrorMetricLabels, I as InvalidationMetricLabels, J as JsonSerializer, L as LayerConfig, p as Logger, M as MetricLayer, P as PrometheusDialCacheMetrics, q as PrometheusMetricsOptions, R as RedisCachePayload, r as RedisClientFactory, s as RedisConfig, t as RedisInvalidationRequest, u as RedisReadRequest, v as RedisWriteRequest, w as SerializationMetricLabels, x as createPrometheusDialCacheMetrics, y as deterministicRampSampler, z as invalidationPrefix, B as normalizeArgs, F as randomRampSampler, G as redisClusterHashTag } from './config-B7bGp-Xj.js';
|
|
3
|
+
import 'prom-client';
|
|
4
|
+
|
|
5
|
+
declare class DialCacheContext {
|
|
6
|
+
private readonly storage;
|
|
7
|
+
isEnabled(): boolean;
|
|
8
|
+
enable<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
9
|
+
disable<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
10
|
+
private run;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class DialCacheError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
declare class UseCaseIsAlreadyRegisteredError extends DialCacheError {
|
|
17
|
+
constructor(useCase: string);
|
|
18
|
+
}
|
|
19
|
+
declare class UseCaseNameIsReservedError extends DialCacheError {
|
|
20
|
+
constructor(useCase: string);
|
|
21
|
+
}
|
|
22
|
+
declare class MissingKeyConfigError extends DialCacheError {
|
|
23
|
+
constructor(useCase: string);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type CacheKeyArgs = Record<string, string | number | boolean | bigint | null | undefined>;
|
|
27
|
+
type Id = string | number | bigint;
|
|
28
|
+
/** A cache-key spec: a bare id, or an id plus extra (secondary) key dimensions. */
|
|
29
|
+
type CacheKeySpec = Id | {
|
|
30
|
+
readonly id: Id;
|
|
31
|
+
readonly args?: CacheKeyArgs;
|
|
32
|
+
};
|
|
33
|
+
type AnyFn = (...args: never[]) => unknown;
|
|
34
|
+
/** The cached value type, derived from the wrapped function's return. */
|
|
35
|
+
type CachedValue<Fn extends AnyFn> = Awaited<ReturnType<Fn>>;
|
|
36
|
+
type CacheKeySelector<Fn extends AnyFn> = (...args: Parameters<Fn>) => CacheKeySpec;
|
|
37
|
+
interface CachedOptions<Fn extends AnyFn> {
|
|
38
|
+
readonly keyType: string;
|
|
39
|
+
readonly useCase: string;
|
|
40
|
+
readonly defaultConfig?: DialCacheKeyConfig | null;
|
|
41
|
+
readonly serializer?: Serializer<CachedValue<Fn>> | null;
|
|
42
|
+
readonly trackForInvalidation?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Select every input dimension that can affect the returned value. Concurrent
|
|
45
|
+
* enabled calls with the same cache key may share one in-flight execution.
|
|
46
|
+
*/
|
|
47
|
+
readonly cacheKey: CacheKeySelector<Fn>;
|
|
48
|
+
}
|
|
49
|
+
type CachedFn<Fn extends AnyFn> = (...args: Parameters<Fn>) => Promise<CachedValue<Fn>>;
|
|
50
|
+
declare class DialCache {
|
|
51
|
+
private readonly context;
|
|
52
|
+
private readonly localCache;
|
|
53
|
+
private readonly useCases;
|
|
54
|
+
private readonly configProvider;
|
|
55
|
+
private readonly urnPrefix;
|
|
56
|
+
private readonly logger;
|
|
57
|
+
private readonly rampSampler;
|
|
58
|
+
private readonly redisCache;
|
|
59
|
+
private readonly metrics;
|
|
60
|
+
private readonly inFlight;
|
|
61
|
+
constructor(config?: DialCacheConfig);
|
|
62
|
+
enable<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
63
|
+
disable<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
64
|
+
withEnabled<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
65
|
+
withDisabled<T>(fn: () => Awaitable<T>): Promise<T>;
|
|
66
|
+
isEnabled(): boolean;
|
|
67
|
+
cached<Fn extends AnyFn>(fn: Fn, options: CachedOptions<Fn>): CachedFn<Fn>;
|
|
68
|
+
/**
|
|
69
|
+
* Writes a remote invalidation watermark for Redis-tracked entries.
|
|
70
|
+
*
|
|
71
|
+
* This does not synchronously evict local cache hits or untracked Redis values.
|
|
72
|
+
*
|
|
73
|
+
* @param futureBufferMs Nonnegative safe integer covering source lag and stale fallback work through the Redis write.
|
|
74
|
+
*/
|
|
75
|
+
invalidateRemote(keyType: string, id: Id, futureBufferMs?: number): Promise<void>;
|
|
76
|
+
flushAll(): Promise<void>;
|
|
77
|
+
private getThroughLocalOnly;
|
|
78
|
+
private getThroughRedisChain;
|
|
79
|
+
private getThroughRemoteAfterLocal;
|
|
80
|
+
private finishRedisChain;
|
|
81
|
+
private readLocal;
|
|
82
|
+
private resolveRemoteLayerConfig;
|
|
83
|
+
private readRemote;
|
|
84
|
+
private readRemoteWithResolvedConfig;
|
|
85
|
+
private putLocalFailOpen;
|
|
86
|
+
private callFallback;
|
|
87
|
+
private recordError;
|
|
88
|
+
private registerUseCase;
|
|
89
|
+
private buildKey;
|
|
90
|
+
private singleFlight;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type CacheKeySpec, type CachedFn, type CachedOptions, type CachedValue, DialCache, DialCacheConfig, DialCacheContext, DialCacheError, DialCacheKeyConfig, MissingKeyConfigError, Serializer, UseCaseIsAlreadyRegisteredError, UseCaseNameIsReservedError };
|