@dcsv-io/d2-caching-abstractions 0.1.1 → 0.1.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 +19 -12
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Copyright (c) DCSV. Licensed under the Apache License, Version 2.0.
|
|
|
4
4
|
|
|
5
5
|
# @dcsv-io/d2-caching-abstractions
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
.NET mirror: `DcsvIo.D2.Caching.Abstractions`
|
|
8
8
|
|
|
9
9
|
Node/BFF authors inject these cache **ports** without pulling Redis, logging, or DI
|
|
10
10
|
wiring into domain-safe code. The package is the TypeScript twin of
|
|
@@ -16,6 +16,12 @@ wiring into domain-safe code. The package is the TypeScript twin of
|
|
|
16
16
|
`Promise<D2Result<…>>` / `D2Result<…>` via `@dcsv-io/d2-result`. **No implementations**
|
|
17
17
|
ship here — only contracts and pure helpers.
|
|
18
18
|
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @dcsv-io/d2-caching-abstractions
|
|
23
|
+
```
|
|
24
|
+
|
|
19
25
|
## Public surface — building blocks
|
|
20
26
|
|
|
21
27
|
Fine-grained interfaces. Implementations declare which they support; marker
|
|
@@ -24,12 +30,12 @@ cancellation is optional `signal?: AbortSignal`; durations are milliseconds
|
|
|
24
30
|
(`expirationMs`, `defaultExpirationMs`, remaining TTL from `getTtl`).
|
|
25
31
|
|
|
26
32
|
- **`ICacheBasic`** — `get` / `getMany` / `exists` / `getTtl` / `set` /
|
|
27
|
-
|
|
33
|
+
`setMany` / `remove` / `removeMany`
|
|
28
34
|
- **`ICacheAtomic`** — `setNx` / `increment` / `acquireLock` / `releaseLock`
|
|
29
35
|
- **`ICacheBroadcast`** — `setAndBroadcast` / `setManyAndBroadcast` /
|
|
30
|
-
|
|
36
|
+
`removeAndBroadcast` / `removeManyAndBroadcast`
|
|
31
37
|
- **`ICacheSet`** — `setAdd` / `setCardinality` / `setRemove` / `setContains`
|
|
32
|
-
|
|
38
|
+
(cluster-only — Redis SADD/SCARD/SREM/SISMEMBER)
|
|
33
39
|
|
|
34
40
|
All operations return `D2Result` / `D2Result<T>` (async ops wrap in
|
|
35
41
|
`Promise`). Multi-entry maps use `ReadonlyMap<string, T>` (callers may
|
|
@@ -189,8 +195,9 @@ const subscription = backplane.subscribe(async (key, signal) => {
|
|
|
189
195
|
await dropLocal(key, signal);
|
|
190
196
|
});
|
|
191
197
|
|
|
192
|
-
// Later:
|
|
193
|
-
|
|
198
|
+
// Later — dispose the subscription (AsyncDisposable):
|
|
199
|
+
const dispose = subscription[Symbol.asyncDispose];
|
|
200
|
+
await dispose.call(subscription);
|
|
194
201
|
```
|
|
195
202
|
|
|
196
203
|
## Atomic on tiered — how it works
|
|
@@ -201,7 +208,7 @@ the atomicity guarantee comes from L2 (the cluster source of truth). Pattern:
|
|
|
201
208
|
- **`increment`** → L2 atomic increment; on success invalidate L1 + broadcast.
|
|
202
209
|
- **`setNx`** → L2 SetNx; on success write L1 + broadcast; on fail invalidate L1.
|
|
203
210
|
- **`acquireLock` / `releaseLock`** → pure delegation to L2 (lock state is
|
|
204
|
-
|
|
211
|
+
coordination, not a cached value).
|
|
205
212
|
|
|
206
213
|
L1 is never authoritative for atomic state. L2 is. L1 just reflects (or
|
|
207
214
|
invalidates). Concrete behavior lands in `@dcsv-io/d2-caching-tiered`.
|
|
@@ -255,9 +262,9 @@ No runtime deps beyond those (no DI, no logging, no provider libs). This
|
|
|
255
262
|
abstraction stays domain-safe so any handler can declare a cache dependency
|
|
256
263
|
without dragging in implementation runtime.
|
|
257
264
|
|
|
258
|
-
##
|
|
265
|
+
## Sister packages
|
|
259
266
|
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
-
|
|
263
|
-
- .NET twin: `
|
|
267
|
+
- `@dcsv-io/d2-caching-local-default` — local in-process impl
|
|
268
|
+
- `@dcsv-io/d2-caching-distributed-redis` — Redis + backplane
|
|
269
|
+
- `@dcsv-io/d2-caching-tiered` — L1+L2 composition
|
|
270
|
+
- .NET twin: `DcsvIo.D2.Caching.Abstractions`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcsv-io/d2-caching-abstractions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@dcsv-io/d2-i18n-keys": "0.1.
|
|
18
|
-
"@dcsv-io/d2-result": "0.1.
|
|
17
|
+
"@dcsv-io/d2-i18n-keys": "0.1.2",
|
|
18
|
+
"@dcsv-io/d2-result": "0.1.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@vitest/coverage-v8": "4.0.18",
|