@open-mercato/cache-provider-memcached 0.0.0-stage → 0.11.1-develop.9002.1.e180dacef1
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 +166 -2
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +7 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +7 -0
- package/dist/layout.js +101 -0
- package/dist/layout.js.map +7 -0
- package/dist/protocol/client.js +164 -0
- package/dist/protocol/client.js.map +7 -0
- package/dist/protocol/commands.js +292 -0
- package/dist/protocol/commands.js.map +7 -0
- package/dist/protocol/connection.js +114 -0
- package/dist/protocol/connection.js.map +7 -0
- package/dist/protocol/errors.js +28 -0
- package/dist/protocol/errors.js.map +7 -0
- package/dist/protocol/index.js +37 -0
- package/dist/protocol/index.js.map +7 -0
- package/dist/protocol/reader.js +75 -0
- package/dist/protocol/reader.js.map +7 -0
- package/dist/protocol/transport.js +65 -0
- package/dist/protocol/transport.js.map +7 -0
- package/dist/provider.js +47 -0
- package/dist/provider.js.map +7 -0
- package/dist/settings.js +49 -0
- package/dist/settings.js.map +7 -0
- package/dist/strategy.js +342 -0
- package/dist/strategy.js.map +7 -0
- package/package.json +67 -3
- package/src/errors.ts +59 -0
- package/src/index.ts +19 -0
- package/src/layout.ts +140 -0
- package/src/protocol/client.ts +201 -0
- package/src/protocol/commands.ts +338 -0
- package/src/protocol/connection.ts +138 -0
- package/src/protocol/errors.ts +44 -0
- package/src/protocol/index.ts +37 -0
- package/src/protocol/reader.ts +90 -0
- package/src/protocol/transport.ts +107 -0
- package/src/provider.ts +54 -0
- package/src/settings.ts +55 -0
- package/src/strategy.ts +423 -0
package/README.md
CHANGED
|
@@ -1,3 +1,167 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-mercato/cache-provider-memcached
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Open Mercato cache provider (`open-mercato/memcached`) for **one loopback-only Memcached server**. It plugs into the `@open-mercato/cache` v1 provider host: tenant scoping, tag invalidation, TTL, enumeration, stats, cleanup and readiness all keep working through the regular `cache` DI service.
|
|
4
|
+
|
|
5
|
+
Memcached has no tags, no key enumeration and no server-side sets, so this provider stores entries in **fixed CAS buckets**: a namespace owns `bucketCount` memcached items, each holding its own entries, tags and per-entry logical expiry. Every mutation reads a bucket and writes it back with compare-and-swap.
|
|
6
|
+
|
|
7
|
+
- Server-only and ESM, with types. The only runtime dependency is `zod`. `@open-mercato/cache` is a peer dependency.
|
|
8
|
+
- Uses its own small client over `node:net`, speaking the memcached text/meta protocol (`mg`/`ms`/`md`/`mn` plus `gets`/`cas`/`add`). It is exported as `@open-mercato/cache-provider-memcached/protocol` for reuse. The npm clients were not usable here: `memjs` has no `gets`/`cas`, and `memcached` has been unmaintained since 2016.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
yarn add @open-mercato/cache-provider-memcached
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Add the registration to the app's `src/providers/cache.ts`, then run `yarn generate`.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import type { CacheProviderRegistration } from '@open-mercato/cache/provider'
|
|
20
|
+
|
|
21
|
+
export const cacheProviders: CacheProviderRegistration[] = [
|
|
22
|
+
{
|
|
23
|
+
id: 'open-mercato/memcached',
|
|
24
|
+
load: () => import('@open-mercato/cache-provider-memcached').then((mod) => mod.provider),
|
|
25
|
+
settings: () => ({
|
|
26
|
+
host: process.env.MEMCACHED_HOST ?? '127.0.0.1',
|
|
27
|
+
port: Number(process.env.MEMCACHED_PORT ?? 11211),
|
|
28
|
+
bucketCount: 64,
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Then select it:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
CACHE_PROVIDER=open-mercato/memcached
|
|
38
|
+
CACHE_PROVIDER_NAMESPACE=prod-eu-1 # stable per deployment; 1-64 chars [A-Za-z0-9._-]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Docker recipe (the qualified image):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
docker run -d --name om-memcached -p 127.0.0.1:11211:11211 memcached:1.6.45-alpine memcached -m 256
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The provider reports `local` placement. Keep the daemon bound to loopback or publish its container port only on loopback.
|
|
48
|
+
|
|
49
|
+
## Settings
|
|
50
|
+
|
|
51
|
+
The schema is strict: unknown keys are rejected, including TLS, SASL and multi-server options. Those profiles are not qualified yet (see [Supported matrix](#supported-matrix)).
|
|
52
|
+
|
|
53
|
+
| Setting | Default | Bounds | Meaning |
|
|
54
|
+
|---|---|---|---|
|
|
55
|
+
| `host` | — (required) | `127.0.0.1` or `::1` | Literal loopback address |
|
|
56
|
+
| `port` | `11211` | 1–65535 | |
|
|
57
|
+
| `bucketCount` | `64` | 1–4096 | Fixed number of bucket items per namespace. Part of the key layout (see below). |
|
|
58
|
+
| `maxItemBytes` | `1048576` | 4 KiB–128 MiB | Upper bound for one encoded bucket. The lower of this and the server's `item_size_max` (`-I`) is used. |
|
|
59
|
+
| `casRetries` | `16` | 1–100 | Compare-and-swap attempts per bucket commit before failing with `cas_conflict` |
|
|
60
|
+
| `casBackoffMs` | `4` | 0–1000 | Base for randomized exponential backoff between CAS attempts |
|
|
61
|
+
| `poolSize` | `2` | 1–32 | Pipelined TCP connections |
|
|
62
|
+
| `connectTimeoutMs` | `2000` | 50–60000 | Connect deadline |
|
|
63
|
+
| `commandTimeoutMs` | `2000` | 50–60000 | Per-command deadline. A timeout resets the connection. |
|
|
64
|
+
| `maxCommandBytes` | `16384` | 256–16384 | Upper bound on the command text of one batched multi-get |
|
|
65
|
+
| `enumerationBatchSize` | `16` | 1–256 | Buckets fetched per enumeration round trip. This bounds memory during `keys`, `stats`, `deleteByTags`, `clear` and `cleanup`. |
|
|
66
|
+
|
|
67
|
+
`redact()` reports `host`, `port`, `transport`, `bucketCount`, `maxItemBytes`, `casRetries`, `poolSize` and the timeouts. There are no credentials in this profile.
|
|
68
|
+
|
|
69
|
+
## Data model
|
|
70
|
+
|
|
71
|
+
- **Bucket key:** `{namespace}:v1:b{bucketCount}:{index}`, where `index = sha256(routingKey)[0..4] mod bucketCount`. Including the bucket count in the key means a changed count starts an empty layout. It can never read entries routed by a different modulus. Still, treat a bucket-count change like a layout change and use a new namespace for it (see the spec's cutover rules).
|
|
72
|
+
- **Bucket item:** JSON `{"v":1,"e":{ "<physicalKey>": { p, b?, t, x, c } }}`:
|
|
73
|
+
- `p`: payload, encoded by the host codec. Compressed frames are stored as base64 with `b: 1`.
|
|
74
|
+
- `t`: scoped tags.
|
|
75
|
+
- `x`: logical expiry in epoch ms.
|
|
76
|
+
- `c`: creation time.
|
|
77
|
+
|
|
78
|
+
The memcached item itself is stored without an expiry.
|
|
79
|
+
- **Coherent records:** the host stores the value and its enumeration metadata together in one record. Each record is stored in exactly one bucket.
|
|
80
|
+
- **Writes:** mutations to one bucket within a process are coalesced (up to 64 per commit) and committed with these steps:
|
|
81
|
+
1. `mg` (value + CAS).
|
|
82
|
+
2. Apply the queued mutations, then reclaim entries whose logical expiry has passed.
|
|
83
|
+
3. `ms … C<cas>`. A bucket that does not exist yet is created with `ms … ME` (atomic add). A bucket that becomes empty is removed with `md … C<cas>`.
|
|
84
|
+
4. On `EX`, `NS` or `NF`, re-read the latest state and retry with jittered backoff, up to `casRetries`.
|
|
85
|
+
- **Concurrent retagging:** invalidation predicates (`deleteByTags`, `clear`, `cleanup`) are evaluated against the bucket state read inside the CAS loop. An entry that another process retagged in the meantime is therefore never deleted.
|
|
86
|
+
- **Enumeration** (`keys`, `stats`, `deleteByTags`, `clear`, `cleanup`) fetches every bucket key of the namespace with quiet `mg … k q` pipelines terminated by `mn`. Each batch holds at most `enumerationBatchSize` buckets and at most 16 KiB of command text.
|
|
87
|
+
- **A missing or evicted bucket** is a miss for all its entries. An undecodable bucket is treated as empty and overwritten on the next write. An undecodable entry is a miss and is removed with a conditional write.
|
|
88
|
+
- **Logical expiry:** expired entries remain readable with `returnExpired` until the next write to their bucket or `cleanup()` reclaims them.
|
|
89
|
+
|
|
90
|
+
## Errors
|
|
91
|
+
|
|
92
|
+
Errors never include endpoints, keys or values.
|
|
93
|
+
|
|
94
|
+
| Condition | Error |
|
|
95
|
+
|---|---|
|
|
96
|
+
| Server unreachable or connection lost | `CacheProviderError` `unavailable` |
|
|
97
|
+
| Command or connect deadline exceeded | `CacheProviderError` `timeout`. The outcome of an in-flight write is unknown. |
|
|
98
|
+
| Value too large for one item (after encoding) | `MemcachedCacheError` `item_too_large`. The previous copy of that key is removed first (a conditional bucket write), so a stale value is never served. Other entries are untouched. Through the cache service the error arrives as a sanitized `CacheProviderError` (`unavailable`) with the original as `originalError`. |
|
|
99
|
+
| Bucket still contended after `casRetries` | `MemcachedCacheError` `cas_conflict` |
|
|
100
|
+
| Server item limit smaller than the bucket envelope | `MemcachedCacheError` `incompatible_server` (from `healthcheck`) |
|
|
101
|
+
| Unexpected or malformed server reply | `MemcachedCacheError` `protocol_error`. The connection is reset. |
|
|
102
|
+
| Invalid settings | `CacheProviderError` `invalid_settings`, with field paths only |
|
|
103
|
+
|
|
104
|
+
## Supported matrix
|
|
105
|
+
|
|
106
|
+
| Profile | Status | Evidence |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| One loopback-only Memcached 1.6 server, plain TCP | **Supported** | `memcached:1.6.45-alpine` (linux/arm64), see Evidence |
|
|
109
|
+
| Multiple servers (client-side routing) | Unverified, not offered | No settings for it. Needs identical routing across clients and per-server qualification. |
|
|
110
|
+
| SASL authentication | Unverified, not offered | Not implemented. The meta protocol over the text port has no SASL. |
|
|
111
|
+
| TLS (`-Z`, memcached built with TLS) | Unverified, not offered | `createTlsTransport` exists in `./protocol` for later profiles but is not reachable from settings or qualified |
|
|
112
|
+
| Memcached < 1.6 (no meta commands) | Not supported | The bucket layout needs `mg`/`ms`/`md` |
|
|
113
|
+
|
|
114
|
+
## Limitations and operating envelope
|
|
115
|
+
|
|
116
|
+
- **Capacity per namespace** is roughly `bucketCount × item_size_max`, where `item_size_max` is `min(maxItemBytes, -I)` minus the bucket envelope: about 64 MiB with the defaults (64 × 1 MiB). Adding server memory (`-m`) does not raise it. Only `bucketCount` (with a new namespace) or the item limit does. When a bucket would exceed its item limit, the provider evicts that bucket's **oldest entries** to make room and logs a rate-limited warning (`capacityEvictions` in `diagnostics()`). A single value that cannot fit even in an empty bucket fails with `item_too_large`.
|
|
117
|
+
- **Memcached LRU eviction** drops whole buckets, so every entry routed to an evicted bucket becomes a miss at once. Under memory pressure, any bucket rewrite (including one done by `deleteByTags`) may cause the server to evict other buckets. Size `-m` well above the working set of `bucketCount × typical bucket size`.
|
|
118
|
+
- **Restarts and flushes** lose the whole cache. After a server restart the provider reconnects on the next command. The suite shows a whole-namespace miss followed by normal operation.
|
|
119
|
+
- **Read amplification:** every `get`/`has` fetches the **whole bucket** item and decodes it to return one entry. With the defaults a read moves up to 1 MiB for a 1 KiB value once buckets fill up. Read latency and network traffic grow with bucket fill, not with value size. Keep buckets small by raising `bucketCount` for large working sets, and prefer the Valkey/Redis providers for read-heavy caches with many entries.
|
|
120
|
+
- **Write cost:** each logical `set` updates one record by rewriting the bucket through CAS. Large buckets therefore make writes more expensive. Raise `bucketCount` for larger working sets.
|
|
121
|
+
- **Enumeration cost:** `deleteByTags`, `clear`, `keys`, `stats` and `cleanup` read the whole namespace (`bucketCount` items). Their latency grows with total namespace bytes, not with the number of matches. The host's `keys()` then reads one bucket per listed key.
|
|
122
|
+
- **Logical expiry** is reclaimed on bucket writes and by `cleanup()`. Schedule `cleanup()` if many entries expire without being rewritten.
|
|
123
|
+
- **Contention:** at most one commit per bucket is in flight per process. Cross-process conflicts are resolved by CAS retries. With 1 bucket and 2 processes × 16 concurrent writers, the suite had conflicts but no retries were exhausted.
|
|
124
|
+
|
|
125
|
+
## Evidence
|
|
126
|
+
|
|
127
|
+
Manual runs on a developer machine, not CI. No CI job runs the container suites yet (see `packages/cache-redis-protocol/README.md` → *Proposed CI job*). Command: `yarn workspace @open-mercato/cache-provider-memcached test:containers` (or `yarn test:cache-providers:containers` from the repo root). Recorded 2026-11-24 on Docker 29.9.2 (linux/arm64, macOS host, 8 GB VM), Node v26.12.1, Testcontainers 12.1.0.
|
|
128
|
+
|
|
129
|
+
| Suite | Image@tag | Topology / server flags | Auth/TLS | Result |
|
|
130
|
+
|---|---|---|---|---|
|
|
131
|
+
| Shared conformance kit, 64 buckets (default): 16 tests incl. independent process, corrupt value, `returnExpired`, 601-entry batch boundary | `memcached:1.6.45-alpine` | 1 server, `-m 64` | none | 16/16 pass |
|
|
132
|
+
| Shared conformance kit, 1 bucket (maximum contention) | `memcached:1.6.45-alpine` | 1 server, `-m 64` | none | 16/16 pass |
|
|
133
|
+
| Engine: logical TTL + reclaim + cleanup counts, CAS contention from 2 processes on 1 bucket (600 writes, conflicts > 0, 0 lost, 0 exhausted), concurrent retag vs invalidation across 2 processes, unreachable server | `memcached:1.6.45-alpine` | 1 server, `-m 64` | none | 4/4 pass |
|
|
134
|
+
| Engine: oversize writes (`item_too_large`, stale copy of the key dropped, other entries intact), server-side oversize rejection keeps the connection, bucket capacity eviction | `memcached:1.6.45-alpine` | 1 server, `-m 64 -I 128k -o slab_chunk_max=64` | none | 3/3 pass |
|
|
135
|
+
| Engine: coherent whole-bucket eviction (6000 × 2 KiB entries, 1024 buckets; server `evictions > 0`; every listed key readable and vice versa; tag invalidation afterwards) | `memcached:1.6.45-alpine` | 1 server, `-m 8 -I 128k -o slab_chunk_max=64` | none | 1/1 pass |
|
|
136
|
+
| Engine: server restart (whole-namespace miss, reconnect, recovery on next writes) | `memcached:1.6.45-alpine` | 1 server, `-m 32`, fixed host port, `docker restart` | none | 1/1 pass |
|
|
137
|
+
| Packed install of this package and the cache host with its default providers into a fresh app, consumer type-check, registration → `resolveCacheProvider` → cache workflow | `memcached:1.6.45-alpine` | 1 server, `-m 32` | none | 3/3 pass |
|
|
138
|
+
| Unit (no Docker): settings schema, redaction, key layout and routing, protocol parser and batching, oversize overwrite drops the previous copy | — | — | — | 22/22 pass |
|
|
139
|
+
|
|
140
|
+
Full run: **66/66 tests passed** (22 unit + 44 container), `OM_CACHE_PROVIDER_CONTAINER_TESTS=1 jest --runInBand`. The container suite took about 15 s. Last rerun 2026-11-24 after the oversize change.
|
|
141
|
+
|
|
142
|
+
### Performance qualification
|
|
143
|
+
|
|
144
|
+
Produced by `node scripts/qualify.mjs`:
|
|
145
|
+
|
|
146
|
+
- **Setup:** two independent client processes run concurrently, each doing 4000 operations at concurrency 8. The mix is 70% `get`, 25% `set` (2 tags from a pool of 50) and 5% `deleteByTags` (1 random tag), over 2000 keys with a 512 B payload, in one tenant. Server: `memcached:1.6.45-alpine -m 256`. Reference: `redis:7.4.2-alpine` running the stock strategy.
|
|
147
|
+
- **How to read it:** latencies are in ms. Each percentile is the worse of the two clients.
|
|
148
|
+
|
|
149
|
+
| Profile | Errors | Throughput (ops/s, both clients) | get p50 / p95 | set p50 / p95 | deleteByTags p50 / p95 | CAS conflicts (exhausted) | memcached commands / op |
|
|
150
|
+
|---|---|---|---|---|---|---|---|
|
|
151
|
+
| memcached, 64 buckets (default) | 0 | 16 234 | 0.40 / 0.71 | 1.70 / 4.43 | 3.23 / 7.16 | 209 (0) | 2.35 |
|
|
152
|
+
| memcached, 256 buckets | 0 | 14 011 | 0.41 / 0.65 | 1.65 / 2.38 | 8.05 / 10.47 | 56 (0) | 2.97 |
|
|
153
|
+
| memcached, 16 buckets | 0 | 11 733 | 0.44 / 0.86 | 2.25 / 9.78 | 3.20 / 15.58 | 598 (0) | 2.21 |
|
|
154
|
+
| stock redis strategy (reference) | 0 | 33 154 | 0.30 / 0.52 | 0.72 / 1.22 | 1.07 / 1.81 | — | — |
|
|
155
|
+
|
|
156
|
+
Command mix for the 64-bucket profile across both clients: `mg` 13 144, `ms` 5 345, `md` 329.
|
|
157
|
+
|
|
158
|
+
The trade-off: more buckets mean cheaper writes and fewer conflicts, but more expensive namespace enumeration (`deleteByTags`). Fewer buckets mean the opposite. Redis stays roughly 2–3× faster because it updates tag indexes server-side. This is local-loopback data, so re-run it on your own network before relying on it.
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
yarn workspace @open-mercato/cache-provider-memcached test # unit tests, no Docker
|
|
164
|
+
yarn workspace @open-mercato/cache-provider-memcached test:containers # real memcached via Testcontainers
|
|
165
|
+
yarn workspace @open-mercato/cache-provider-memcached qualify # performance qualification (Docker)
|
|
166
|
+
yarn workspace @open-mercato/cache-provider-memcached build
|
|
167
|
+
```
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CacheProviderError, isCacheProviderError } from "@open-mercato/cache/provider";
|
|
2
|
+
import { isMemcachedProtocolError } from "./protocol/errors.js";
|
|
3
|
+
import { MEMCACHED_PROVIDER_ID } from "./settings.js";
|
|
4
|
+
class MemcachedCacheError extends Error {
|
|
5
|
+
constructor(code, message, options = {}) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.providerId = MEMCACHED_PROVIDER_ID;
|
|
8
|
+
this.name = "MemcachedCacheError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
Object.defineProperty(this, "originalError", {
|
|
11
|
+
value: options.cause,
|
|
12
|
+
enumerable: false,
|
|
13
|
+
writable: false,
|
|
14
|
+
configurable: false
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
toJSON() {
|
|
18
|
+
return { name: this.name, code: this.code, message: this.message, providerId: this.providerId };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function isMemcachedCacheError(error) {
|
|
22
|
+
return error instanceof MemcachedCacheError || error instanceof Error && error.name === "MemcachedCacheError" && typeof error.code === "string";
|
|
23
|
+
}
|
|
24
|
+
function toProviderFailure(error) {
|
|
25
|
+
if (isCacheProviderError(error) || isMemcachedCacheError(error)) return error;
|
|
26
|
+
if (isMemcachedProtocolError(error)) {
|
|
27
|
+
switch (error.code) {
|
|
28
|
+
case "timeout":
|
|
29
|
+
return new CacheProviderError("timeout", "Memcached command timed out", { providerId: MEMCACHED_PROVIDER_ID, cause: error });
|
|
30
|
+
case "unavailable":
|
|
31
|
+
case "closed":
|
|
32
|
+
return new CacheProviderError("unavailable", "Memcached server is unavailable", { providerId: MEMCACHED_PROVIDER_ID, cause: error });
|
|
33
|
+
case "item_too_large":
|
|
34
|
+
return new MemcachedCacheError("item_too_large", "Memcached rejected a cache bucket larger than its item size limit", { cause: error });
|
|
35
|
+
default:
|
|
36
|
+
return new MemcachedCacheError("protocol_error", "Memcached returned an unexpected reply", { cause: error });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return new CacheProviderError("unavailable", "Memcached cache operation failed", { providerId: MEMCACHED_PROVIDER_ID, cause: error });
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
MemcachedCacheError,
|
|
43
|
+
isMemcachedCacheError,
|
|
44
|
+
toProviderFailure
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/errors.ts"],
|
|
4
|
+
"sourcesContent": ["import { CacheProviderError, isCacheProviderError } from '@open-mercato/cache/provider'\nimport { isMemcachedProtocolError } from './protocol/errors'\nimport { MEMCACHED_PROVIDER_ID } from './settings'\n\nexport type MemcachedCacheErrorCode = 'item_too_large' | 'cas_conflict' | 'incompatible_server' | 'protocol_error'\n\n/**\n * Provider-specific failures outside the shared `CacheProviderError` codes.\n * Messages never include endpoints, keys or values.\n */\nexport class MemcachedCacheError extends Error {\n public readonly code: MemcachedCacheErrorCode\n public readonly providerId = MEMCACHED_PROVIDER_ID\n declare public readonly originalError?: unknown\n\n constructor(code: MemcachedCacheErrorCode, message: string, options: { cause?: unknown } = {}) {\n super(message)\n this.name = 'MemcachedCacheError'\n this.code = code\n Object.defineProperty(this, 'originalError', {\n value: options.cause,\n enumerable: false,\n writable: false,\n configurable: false,\n })\n }\n\n toJSON(): { name: string; code: MemcachedCacheErrorCode; message: string; providerId: string } {\n return { name: this.name, code: this.code, message: this.message, providerId: this.providerId }\n }\n}\n\nexport function isMemcachedCacheError(error: unknown): error is MemcachedCacheError {\n return error instanceof MemcachedCacheError\n || (error instanceof Error && error.name === 'MemcachedCacheError' && typeof (error as { code?: unknown }).code === 'string')\n}\n\n/**\n * Maps transport and protocol failures onto the shared sanitized contract:\n * `CacheProviderError` (`timeout` / `unavailable`) for transport problems and\n * `MemcachedCacheError` for item limits and protocol violations.\n */\nexport function toProviderFailure(error: unknown): Error {\n if (isCacheProviderError(error) || isMemcachedCacheError(error)) return error\n if (isMemcachedProtocolError(error)) {\n switch (error.code) {\n case 'timeout':\n return new CacheProviderError('timeout', 'Memcached command timed out', { providerId: MEMCACHED_PROVIDER_ID, cause: error })\n case 'unavailable':\n case 'closed':\n return new CacheProviderError('unavailable', 'Memcached server is unavailable', { providerId: MEMCACHED_PROVIDER_ID, cause: error })\n case 'item_too_large':\n return new MemcachedCacheError('item_too_large', 'Memcached rejected a cache bucket larger than its item size limit', { cause: error })\n default:\n return new MemcachedCacheError('protocol_error', 'Memcached returned an unexpected reply', { cause: error })\n }\n }\n return new CacheProviderError('unavailable', 'Memcached cache operation failed', { providerId: MEMCACHED_PROVIDER_ID, cause: error })\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB,4BAA4B;AACzD,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AAQ/B,MAAM,4BAA4B,MAAM;AAAA,EAK7C,YAAY,MAA+B,SAAiB,UAA+B,CAAC,GAAG;AAC7F,UAAM,OAAO;AAJf,SAAgB,aAAa;AAK3B,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,iBAAiB;AAAA,MAC3C,OAAO,QAAQ;AAAA,MACf,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AAAA,EAEA,SAA+F;AAC7F,WAAO,EAAE,MAAM,KAAK,MAAM,MAAM,KAAK,MAAM,SAAS,KAAK,SAAS,YAAY,KAAK,WAAW;AAAA,EAChG;AACF;AAEO,SAAS,sBAAsB,OAA8C;AAClF,SAAO,iBAAiB,uBAClB,iBAAiB,SAAS,MAAM,SAAS,yBAAyB,OAAQ,MAA6B,SAAS;AACxH;AAOO,SAAS,kBAAkB,OAAuB;AACvD,MAAI,qBAAqB,KAAK,KAAK,sBAAsB,KAAK,EAAG,QAAO;AACxE,MAAI,yBAAyB,KAAK,GAAG;AACnC,YAAQ,MAAM,MAAM;AAAA,MAClB,KAAK;AACH,eAAO,IAAI,mBAAmB,WAAW,+BAA+B,EAAE,YAAY,uBAAuB,OAAO,MAAM,CAAC;AAAA,MAC7H,KAAK;AAAA,MACL,KAAK;AACH,eAAO,IAAI,mBAAmB,eAAe,mCAAmC,EAAE,YAAY,uBAAuB,OAAO,MAAM,CAAC;AAAA,MACrI,KAAK;AACH,eAAO,IAAI,oBAAoB,kBAAkB,qEAAqE,EAAE,OAAO,MAAM,CAAC;AAAA,MACxI;AACE,eAAO,IAAI,oBAAoB,kBAAkB,0CAA0C,EAAE,OAAO,MAAM,CAAC;AAAA,IAC/G;AAAA,EACF;AACA,SAAO,IAAI,mBAAmB,eAAe,oCAAoC,EAAE,YAAY,uBAAuB,OAAO,MAAM,CAAC;AACtI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { provider, createMemcachedCacheStrategy } from "./provider.js";
|
|
2
|
+
import { provider as provider2 } from "./provider.js";
|
|
3
|
+
import {
|
|
4
|
+
MEMCACHED_PROVIDER_ID,
|
|
5
|
+
MEMCACHED_SETTINGS_DEFAULTS,
|
|
6
|
+
memcachedSettingsSchema,
|
|
7
|
+
redactMemcachedSettings
|
|
8
|
+
} from "./settings.js";
|
|
9
|
+
import { MemcachedCacheError, isMemcachedCacheError } from "./errors.js";
|
|
10
|
+
import {
|
|
11
|
+
LAYOUT_VERSION,
|
|
12
|
+
bucketItemKey,
|
|
13
|
+
bucketItemKeyFor,
|
|
14
|
+
bucketIndexFor,
|
|
15
|
+
routingKey
|
|
16
|
+
} from "./layout.js";
|
|
17
|
+
export {
|
|
18
|
+
LAYOUT_VERSION,
|
|
19
|
+
MEMCACHED_PROVIDER_ID,
|
|
20
|
+
MEMCACHED_SETTINGS_DEFAULTS,
|
|
21
|
+
MemcachedCacheError,
|
|
22
|
+
bucketIndexFor,
|
|
23
|
+
bucketItemKey,
|
|
24
|
+
bucketItemKeyFor,
|
|
25
|
+
createMemcachedCacheStrategy,
|
|
26
|
+
provider2 as default,
|
|
27
|
+
isMemcachedCacheError,
|
|
28
|
+
memcachedSettingsSchema,
|
|
29
|
+
provider,
|
|
30
|
+
redactMemcachedSettings,
|
|
31
|
+
routingKey
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { provider, createMemcachedCacheStrategy, type CreateMemcachedCacheStrategyOptions } from './provider'\nexport { provider as default } from './provider'\nexport {\n MEMCACHED_PROVIDER_ID,\n MEMCACHED_SETTINGS_DEFAULTS,\n memcachedSettingsSchema,\n redactMemcachedSettings,\n type MemcachedProviderConfig,\n type MemcachedProviderSettingsInput,\n} from './settings'\nexport { MemcachedCacheError, isMemcachedCacheError, type MemcachedCacheErrorCode } from './errors'\nexport {\n LAYOUT_VERSION,\n bucketItemKey,\n bucketItemKeyFor,\n bucketIndexFor,\n routingKey,\n} from './layout'\nexport type { MemcachedCacheStrategy, MemcachedStrategyDiagnostics } from './strategy'\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,oCAA8E;AACjG,SAAqB,YAAZA,iBAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,qBAAqB,6BAA2D;AACzF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
|
+
"names": ["provider"]
|
|
7
|
+
}
|
package/dist/layout.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
const LAYOUT_VERSION = "v1";
|
|
3
|
+
const BUCKET_FORMAT_VERSION = 1;
|
|
4
|
+
const ITEM_OVERHEAD_BYTES = 192;
|
|
5
|
+
const WRAPPER_RECORD_PATTERN = /^(.*):key:(?:k|meta):([0-9a-f]{64})$/;
|
|
6
|
+
function bucketItemKey(namespace, bucketCount, index) {
|
|
7
|
+
return `${namespace}:${LAYOUT_VERSION}:b${bucketCount}:${index}`;
|
|
8
|
+
}
|
|
9
|
+
function allBucketItemKeys(namespace, bucketCount) {
|
|
10
|
+
return Array.from({ length: bucketCount }, (_, index) => bucketItemKey(namespace, bucketCount, index));
|
|
11
|
+
}
|
|
12
|
+
function routingKey(physicalKey) {
|
|
13
|
+
const match = WRAPPER_RECORD_PATTERN.exec(physicalKey);
|
|
14
|
+
return match ? `${match[1]}:key:${match[2]}` : physicalKey;
|
|
15
|
+
}
|
|
16
|
+
function bucketIndexFor(physicalKey, bucketCount) {
|
|
17
|
+
const digest = createHash("sha256").update(routingKey(physicalKey), "utf8").digest();
|
|
18
|
+
return digest.readUInt32BE(0) % bucketCount;
|
|
19
|
+
}
|
|
20
|
+
function bucketItemKeyFor(namespace, bucketCount, physicalKey) {
|
|
21
|
+
return bucketItemKey(namespace, bucketCount, bucketIndexFor(physicalKey, bucketCount));
|
|
22
|
+
}
|
|
23
|
+
function isStoredEntry(value) {
|
|
24
|
+
if (typeof value !== "object" || value === null) return false;
|
|
25
|
+
const record = value;
|
|
26
|
+
return typeof record.p === "string" && (record.b === void 0 || record.b === 1) && Array.isArray(record.t) && record.t.every((tag) => typeof tag === "string") && (record.x === null || typeof record.x === "number") && typeof record.c === "number";
|
|
27
|
+
}
|
|
28
|
+
function decodeBucket(raw) {
|
|
29
|
+
let parsed;
|
|
30
|
+
try {
|
|
31
|
+
parsed = JSON.parse(raw.toString("utf8"));
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
36
|
+
const record = parsed;
|
|
37
|
+
if (record.v !== BUCKET_FORMAT_VERSION || typeof record.e !== "object" || record.e === null || Array.isArray(record.e)) return null;
|
|
38
|
+
const entries = /* @__PURE__ */ new Map();
|
|
39
|
+
for (const [key, entry] of Object.entries(record.e)) {
|
|
40
|
+
if (isStoredEntry(entry)) entries.set(key, entry);
|
|
41
|
+
}
|
|
42
|
+
return entries;
|
|
43
|
+
}
|
|
44
|
+
function encodeBucket(entries) {
|
|
45
|
+
const body = {};
|
|
46
|
+
for (const [key, entry] of entries) body[key] = entry;
|
|
47
|
+
return Buffer.from(JSON.stringify({ v: BUCKET_FORMAT_VERSION, e: body }), "utf8");
|
|
48
|
+
}
|
|
49
|
+
function estimateEntryBytes(key, entry) {
|
|
50
|
+
return Buffer.byteLength(JSON.stringify(key), "utf8") + Buffer.byteLength(JSON.stringify(entry), "utf8") + 2;
|
|
51
|
+
}
|
|
52
|
+
const BUCKET_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ v: BUCKET_FORMAT_VERSION, e: {} }), "utf8");
|
|
53
|
+
function isEntryExpired(entry, now) {
|
|
54
|
+
return entry.x !== null && entry.x <= now;
|
|
55
|
+
}
|
|
56
|
+
function fitBucket(entries, limitBytes, protectedRoutes) {
|
|
57
|
+
let buffer = encodeBucket(entries);
|
|
58
|
+
if (buffer.length <= limitBytes) return { buffer, evicted: 0 };
|
|
59
|
+
const groups = /* @__PURE__ */ new Map();
|
|
60
|
+
for (const [key, entry] of entries) {
|
|
61
|
+
const route = routingKey(key);
|
|
62
|
+
if (protectedRoutes.has(route)) continue;
|
|
63
|
+
const group = groups.get(route) ?? { keys: [], newest: 0, bytes: 0 };
|
|
64
|
+
group.keys.push(key);
|
|
65
|
+
group.newest = Math.max(group.newest, entry.c);
|
|
66
|
+
group.bytes += estimateEntryBytes(key, entry);
|
|
67
|
+
groups.set(route, group);
|
|
68
|
+
}
|
|
69
|
+
const ordered = Array.from(groups.values()).sort((left, right) => left.newest - right.newest);
|
|
70
|
+
let excess = buffer.length - limitBytes;
|
|
71
|
+
let evicted = 0;
|
|
72
|
+
for (const group of ordered) {
|
|
73
|
+
for (const key of group.keys) entries.delete(key);
|
|
74
|
+
evicted += group.keys.length;
|
|
75
|
+
excess -= group.bytes;
|
|
76
|
+
if (excess <= 0) {
|
|
77
|
+
buffer = encodeBucket(entries);
|
|
78
|
+
if (buffer.length <= limitBytes) return { buffer, evicted };
|
|
79
|
+
excess = buffer.length - limitBytes;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
buffer = encodeBucket(entries);
|
|
83
|
+
return buffer.length <= limitBytes ? { buffer, evicted } : null;
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
BUCKET_ENVELOPE_BYTES,
|
|
87
|
+
BUCKET_FORMAT_VERSION,
|
|
88
|
+
ITEM_OVERHEAD_BYTES,
|
|
89
|
+
LAYOUT_VERSION,
|
|
90
|
+
allBucketItemKeys,
|
|
91
|
+
bucketIndexFor,
|
|
92
|
+
bucketItemKey,
|
|
93
|
+
bucketItemKeyFor,
|
|
94
|
+
decodeBucket,
|
|
95
|
+
encodeBucket,
|
|
96
|
+
estimateEntryBytes,
|
|
97
|
+
fitBucket,
|
|
98
|
+
isEntryExpired,
|
|
99
|
+
routingKey
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/layout.ts"],
|
|
4
|
+
"sourcesContent": ["import { createHash } from 'node:crypto'\n\nexport const LAYOUT_VERSION = 'v1'\nexport const BUCKET_FORMAT_VERSION = 1\n/** Per-item bytes memcached spends on its header, key and CAS beyond the value. */\nexport const ITEM_OVERHEAD_BYTES = 192\n\nconst WRAPPER_RECORD_PATTERN = /^(.*):key:(?:k|meta):([0-9a-f]{64})$/\n\nexport type StoredEntry = {\n /** Encoded payload produced by the host codec. */\n p: string\n /** 1 when `p` is base64 of a binary (compressed) frame. */\n b?: 1\n /** Scoped tags. */\n t: string[]\n /** Logical expiry in epoch milliseconds, or null. */\n x: number | null\n /** Creation time in epoch milliseconds. */\n c: number\n}\n\nexport type BucketEntries = Map<string, StoredEntry>\n\n/**\n * Physical bucket item key: `{namespace}:v1:b{bucketCount}:{index}`. The\n * bucket count is part of the key so a changed count starts a fresh layout\n * instead of reading entries routed by a different modulus.\n */\nexport function bucketItemKey(namespace: string, bucketCount: number, index: number): string {\n return `${namespace}:${LAYOUT_VERSION}:b${bucketCount}:${index}`\n}\n\nexport function allBucketItemKeys(namespace: string, bucketCount: number): string[] {\n return Array.from({ length: bucketCount }, (_, index) => bucketItemKey(namespace, bucketCount, index))\n}\n\n/**\n * Routing identity of a physical key. The tenant wrapper stores a value record\n * (`\u2026:key:k:<hash>`) and a metadata record (`\u2026:key:meta:<hash>`) per logical\n * entry; both route to the same bucket so eviction removes them together.\n */\nexport function routingKey(physicalKey: string): string {\n const match = WRAPPER_RECORD_PATTERN.exec(physicalKey)\n return match ? `${match[1]}:key:${match[2]}` : physicalKey\n}\n\nexport function bucketIndexFor(physicalKey: string, bucketCount: number): number {\n const digest = createHash('sha256').update(routingKey(physicalKey), 'utf8').digest()\n return digest.readUInt32BE(0) % bucketCount\n}\n\nexport function bucketItemKeyFor(namespace: string, bucketCount: number, physicalKey: string): string {\n return bucketItemKey(namespace, bucketCount, bucketIndexFor(physicalKey, bucketCount))\n}\n\nfunction isStoredEntry(value: unknown): value is StoredEntry {\n if (typeof value !== 'object' || value === null) return false\n const record = value as Record<string, unknown>\n return typeof record.p === 'string'\n && (record.b === undefined || record.b === 1)\n && Array.isArray(record.t)\n && record.t.every((tag) => typeof tag === 'string')\n && (record.x === null || typeof record.x === 'number')\n && typeof record.c === 'number'\n}\n\n/** Returns null for an item that is not a readable bucket of this layout. */\nexport function decodeBucket(raw: Buffer): BucketEntries | null {\n let parsed: unknown\n try {\n parsed = JSON.parse(raw.toString('utf8'))\n } catch {\n return null\n }\n if (typeof parsed !== 'object' || parsed === null) return null\n const record = parsed as Record<string, unknown>\n if (record.v !== BUCKET_FORMAT_VERSION || typeof record.e !== 'object' || record.e === null || Array.isArray(record.e)) return null\n const entries: BucketEntries = new Map()\n for (const [key, entry] of Object.entries(record.e as Record<string, unknown>)) {\n if (isStoredEntry(entry)) entries.set(key, entry)\n }\n return entries\n}\n\nexport function encodeBucket(entries: BucketEntries): Buffer {\n const body: Record<string, StoredEntry> = {}\n for (const [key, entry] of entries) body[key] = entry\n return Buffer.from(JSON.stringify({ v: BUCKET_FORMAT_VERSION, e: body }), 'utf8')\n}\n\nexport function estimateEntryBytes(key: string, entry: StoredEntry): number {\n return Buffer.byteLength(JSON.stringify(key), 'utf8') + Buffer.byteLength(JSON.stringify(entry), 'utf8') + 2\n}\n\nexport const BUCKET_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ v: BUCKET_FORMAT_VERSION, e: {} }), 'utf8')\n\nexport function isEntryExpired(entry: StoredEntry, now: number): boolean {\n return entry.x !== null && entry.x <= now\n}\n\n/**\n * Drops the oldest routing groups (value + metadata pairs) not listed in\n * `protectedRoutes` until the encoded bucket fits `limitBytes`. Returns the\n * encoded bucket and the number of physical records evicted, or null when the\n * protected entries alone exceed the limit.\n */\nexport function fitBucket(\n entries: BucketEntries,\n limitBytes: number,\n protectedRoutes: ReadonlySet<string>,\n): { buffer: Buffer; evicted: number } | null {\n let buffer = encodeBucket(entries)\n if (buffer.length <= limitBytes) return { buffer, evicted: 0 }\n const groups = new Map<string, { keys: string[]; newest: number; bytes: number }>()\n for (const [key, entry] of entries) {\n const route = routingKey(key)\n if (protectedRoutes.has(route)) continue\n const group = groups.get(route) ?? { keys: [], newest: 0, bytes: 0 }\n group.keys.push(key)\n group.newest = Math.max(group.newest, entry.c)\n group.bytes += estimateEntryBytes(key, entry)\n groups.set(route, group)\n }\n const ordered = Array.from(groups.values()).sort((left, right) => left.newest - right.newest)\n let excess = buffer.length - limitBytes\n let evicted = 0\n for (const group of ordered) {\n for (const key of group.keys) entries.delete(key)\n evicted += group.keys.length\n excess -= group.bytes\n if (excess <= 0) {\n buffer = encodeBucket(entries)\n if (buffer.length <= limitBytes) return { buffer, evicted }\n excess = buffer.length - limitBytes\n }\n }\n buffer = encodeBucket(entries)\n return buffer.length <= limitBytes ? { buffer, evicted } : null\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAEpB,MAAM,iBAAiB;AACvB,MAAM,wBAAwB;AAE9B,MAAM,sBAAsB;AAEnC,MAAM,yBAAyB;AAsBxB,SAAS,cAAc,WAAmB,aAAqB,OAAuB;AAC3F,SAAO,GAAG,SAAS,IAAI,cAAc,KAAK,WAAW,IAAI,KAAK;AAChE;AAEO,SAAS,kBAAkB,WAAmB,aAA+B;AAClF,SAAO,MAAM,KAAK,EAAE,QAAQ,YAAY,GAAG,CAAC,GAAG,UAAU,cAAc,WAAW,aAAa,KAAK,CAAC;AACvG;AAOO,SAAS,WAAW,aAA6B;AACtD,QAAM,QAAQ,uBAAuB,KAAK,WAAW;AACrD,SAAO,QAAQ,GAAG,MAAM,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,KAAK;AACjD;AAEO,SAAS,eAAe,aAAqB,aAA6B;AAC/E,QAAM,SAAS,WAAW,QAAQ,EAAE,OAAO,WAAW,WAAW,GAAG,MAAM,EAAE,OAAO;AACnF,SAAO,OAAO,aAAa,CAAC,IAAI;AAClC;AAEO,SAAS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aAAa,EAAE,QAAQ,QAAQ,IAAI;AAC7D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { MemcachedConnection } from "./connection.js";
|
|
2
|
+
import { MemcachedProtocolError } from "./errors.js";
|
|
3
|
+
import {
|
|
4
|
+
addCommand,
|
|
5
|
+
casCommand,
|
|
6
|
+
getsCommand,
|
|
7
|
+
metaDeleteCommand,
|
|
8
|
+
metaGetCommand,
|
|
9
|
+
metaGetManyCommand,
|
|
10
|
+
metaSetCommand,
|
|
11
|
+
noopCommand,
|
|
12
|
+
statsCommand,
|
|
13
|
+
versionCommand
|
|
14
|
+
} from "./commands.js";
|
|
15
|
+
const MAX_COMMAND_BYTES = 16 * 1024;
|
|
16
|
+
const DEFAULT_POOL_SIZE = 2;
|
|
17
|
+
const DEFAULT_CONNECT_TIMEOUT_MS = 2e3;
|
|
18
|
+
const DEFAULT_COMMAND_TIMEOUT_MS = 2e3;
|
|
19
|
+
function boundedInteger(value, fallback, min, max) {
|
|
20
|
+
if (value === void 0) return fallback;
|
|
21
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
22
|
+
throw new MemcachedProtocolError("protocol_error", `Memcached client option must be an integer between ${min} and ${max}`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function planKeyBatches(keys, lineBytes, maxCommandBytes, maxKeys) {
|
|
27
|
+
const batches = [];
|
|
28
|
+
let current = [];
|
|
29
|
+
let currentBytes = 0;
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
const bytes = lineBytes(key);
|
|
32
|
+
if (bytes > maxCommandBytes) {
|
|
33
|
+
throw new MemcachedProtocolError("command_too_large", "A single memcached key exceeds the command size limit");
|
|
34
|
+
}
|
|
35
|
+
if (current.length > 0 && (currentBytes + bytes > maxCommandBytes || current.length >= maxKeys)) {
|
|
36
|
+
batches.push(current);
|
|
37
|
+
current = [];
|
|
38
|
+
currentBytes = 0;
|
|
39
|
+
}
|
|
40
|
+
current.push(key);
|
|
41
|
+
currentBytes += bytes;
|
|
42
|
+
}
|
|
43
|
+
if (current.length > 0) batches.push(current);
|
|
44
|
+
return batches;
|
|
45
|
+
}
|
|
46
|
+
const META_GET_MANY_OVERHEAD = "mg v c f k q\r\n".length;
|
|
47
|
+
const META_GET_MANY_TERMINATOR = "mn\r\n".length;
|
|
48
|
+
const GETS_OVERHEAD = "gets\r\n".length;
|
|
49
|
+
function createMemcachedClient(options) {
|
|
50
|
+
const transport = options.transport;
|
|
51
|
+
const poolSize = boundedInteger(options.poolSize, DEFAULT_POOL_SIZE, 1, 64);
|
|
52
|
+
const connectTimeoutMs = boundedInteger(options.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS, 1, 12e4);
|
|
53
|
+
const commandTimeoutMs = boundedInteger(options.commandTimeoutMs, DEFAULT_COMMAND_TIMEOUT_MS, 1, 12e4);
|
|
54
|
+
const maxCommandBytes = boundedInteger(options.maxCommandBytes, MAX_COMMAND_BYTES, 256, MAX_COMMAND_BYTES);
|
|
55
|
+
const maxKeysPerBatch = boundedInteger(options.maxKeysPerBatch, 512, 1, 4096);
|
|
56
|
+
const slots = Array.from({ length: poolSize }, () => null);
|
|
57
|
+
const counts = {
|
|
58
|
+
mg: 0,
|
|
59
|
+
ms: 0,
|
|
60
|
+
md: 0,
|
|
61
|
+
mn: 0,
|
|
62
|
+
gets: 0,
|
|
63
|
+
add: 0,
|
|
64
|
+
cas: 0,
|
|
65
|
+
version: 0,
|
|
66
|
+
stats: 0
|
|
67
|
+
};
|
|
68
|
+
let cursor = 0;
|
|
69
|
+
let closed = false;
|
|
70
|
+
const openSlot = (index) => {
|
|
71
|
+
const opening = MemcachedConnection.open(transport, { connectTimeoutMs, commandTimeoutMs }).then(
|
|
72
|
+
(connection) => {
|
|
73
|
+
if (closed) {
|
|
74
|
+
connection.close();
|
|
75
|
+
throw new MemcachedProtocolError("closed", "Memcached client is closed");
|
|
76
|
+
}
|
|
77
|
+
return connection;
|
|
78
|
+
},
|
|
79
|
+
(error) => {
|
|
80
|
+
if (slots[index] === opening) slots[index] = null;
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
slots[index] = opening;
|
|
85
|
+
return opening;
|
|
86
|
+
};
|
|
87
|
+
const acquire = async () => {
|
|
88
|
+
if (closed) throw new MemcachedProtocolError("closed", "Memcached client is closed");
|
|
89
|
+
const index = cursor;
|
|
90
|
+
cursor = (cursor + 1) % poolSize;
|
|
91
|
+
const slot = slots[index];
|
|
92
|
+
if (slot) {
|
|
93
|
+
const connection = await slot.catch(() => null);
|
|
94
|
+
if (connection && connection.alive) return connection;
|
|
95
|
+
if (slots[index] !== slot) return acquire();
|
|
96
|
+
}
|
|
97
|
+
return openSlot(index);
|
|
98
|
+
};
|
|
99
|
+
const run = async (name, build) => {
|
|
100
|
+
const command = build();
|
|
101
|
+
const connection = await acquire();
|
|
102
|
+
counts[name] += 1;
|
|
103
|
+
return connection.send(command.payload, command.parse);
|
|
104
|
+
};
|
|
105
|
+
const runBatches = async (batches, execute) => {
|
|
106
|
+
const merged = /* @__PURE__ */ new Map();
|
|
107
|
+
for (let start = 0; start < batches.length; start += poolSize) {
|
|
108
|
+
const wave = batches.slice(start, start + poolSize);
|
|
109
|
+
const results = await Promise.all(wave.map(execute));
|
|
110
|
+
for (const result of results) for (const [key, item] of result) merged.set(key, item);
|
|
111
|
+
}
|
|
112
|
+
return merged;
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
metaGet: (key) => run("mg", () => metaGetCommand(key)),
|
|
116
|
+
async metaGetMany(keys) {
|
|
117
|
+
const unique = Array.from(new Set(keys));
|
|
118
|
+
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
119
|
+
const batches = planKeyBatches(
|
|
120
|
+
unique,
|
|
121
|
+
(key) => key.length + META_GET_MANY_OVERHEAD,
|
|
122
|
+
maxCommandBytes - META_GET_MANY_TERMINATOR,
|
|
123
|
+
maxKeysPerBatch
|
|
124
|
+
);
|
|
125
|
+
return runBatches(batches, (batch) => run("mg", () => metaGetManyCommand(batch)));
|
|
126
|
+
},
|
|
127
|
+
metaSet: (key, value, setOptions) => run("ms", () => metaSetCommand(key, value, setOptions)),
|
|
128
|
+
metaDelete: (key, deleteOptions) => run("md", () => metaDeleteCommand(key, deleteOptions)),
|
|
129
|
+
async gets(keys) {
|
|
130
|
+
const unique = Array.from(new Set(keys));
|
|
131
|
+
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
132
|
+
const batches = planKeyBatches(unique, (key) => key.length + 1, maxCommandBytes - GETS_OVERHEAD, maxKeysPerBatch);
|
|
133
|
+
return runBatches(batches, (batch) => run("gets", () => getsCommand(batch)));
|
|
134
|
+
},
|
|
135
|
+
add: (key, value, storeOptions) => run("add", () => addCommand(key, value, storeOptions)),
|
|
136
|
+
cas: (key, value, cas, storeOptions) => run("cas", () => casCommand(key, value, cas, storeOptions)),
|
|
137
|
+
async noop() {
|
|
138
|
+
await run("mn", () => noopCommand());
|
|
139
|
+
},
|
|
140
|
+
version: () => run("version", () => versionCommand()),
|
|
141
|
+
stats: (group) => run("stats", () => statsCommand(group)),
|
|
142
|
+
commandCounts: () => ({ ...counts }),
|
|
143
|
+
describe: () => transport.describe(),
|
|
144
|
+
async close() {
|
|
145
|
+
if (closed) return;
|
|
146
|
+
closed = true;
|
|
147
|
+
const pending = slots.splice(0, slots.length);
|
|
148
|
+
await Promise.all(pending.map(async (slot) => {
|
|
149
|
+
if (!slot) return;
|
|
150
|
+
const connection = await slot.catch(() => null);
|
|
151
|
+
connection?.close();
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export {
|
|
157
|
+
DEFAULT_COMMAND_TIMEOUT_MS,
|
|
158
|
+
DEFAULT_CONNECT_TIMEOUT_MS,
|
|
159
|
+
DEFAULT_POOL_SIZE,
|
|
160
|
+
MAX_COMMAND_BYTES,
|
|
161
|
+
createMemcachedClient,
|
|
162
|
+
planKeyBatches
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/protocol/client.ts"],
|
|
4
|
+
"sourcesContent": ["import { MemcachedConnection } from './connection'\nimport { MemcachedProtocolError } from './errors'\nimport type { MemcachedTransport } from './transport'\nimport {\n addCommand,\n casCommand,\n getsCommand,\n metaDeleteCommand,\n metaGetCommand,\n metaGetManyCommand,\n metaSetCommand,\n noopCommand,\n statsCommand,\n versionCommand,\n type ClassicStoreOptions,\n type ClassicStoreOutcome,\n type EncodedCommand,\n type MemcachedItem,\n type MetaDeleteOutcome,\n type MetaSetOptions,\n type MetaSetOutcome,\n} from './commands'\n\nexport const MAX_COMMAND_BYTES = 16 * 1024\nexport const DEFAULT_POOL_SIZE = 2\nexport const DEFAULT_CONNECT_TIMEOUT_MS = 2_000\nexport const DEFAULT_COMMAND_TIMEOUT_MS = 2_000\n\nexport type MemcachedClientOptions = {\n transport: MemcachedTransport\n poolSize?: number\n connectTimeoutMs?: number\n commandTimeoutMs?: number\n /** Upper bound for the command bytes of one batched request (default and maximum 16 KiB). */\n maxCommandBytes?: number\n /** Upper bound for the number of keys fetched by one batched request. */\n maxKeysPerBatch?: number\n}\n\nexport type MemcachedCommandName = 'mg' | 'ms' | 'md' | 'mn' | 'gets' | 'add' | 'cas' | 'version' | 'stats'\n\nexport type MemcachedClient = {\n metaGet(key: string): Promise<MemcachedItem | null>\n metaGetMany(keys: string[]): Promise<Map<string, MemcachedItem>>\n metaSet(key: string, value: Buffer, options?: MetaSetOptions): Promise<MetaSetOutcome>\n metaDelete(key: string, options?: { cas?: string }): Promise<MetaDeleteOutcome>\n gets(keys: string[]): Promise<Map<string, MemcachedItem>>\n add(key: string, value: Buffer, options?: ClassicStoreOptions): Promise<ClassicStoreOutcome>\n cas(key: string, value: Buffer, cas: string, options?: ClassicStoreOptions): Promise<ClassicStoreOutcome>\n noop(): Promise<void>\n version(): Promise<string>\n stats(group?: string): Promise<Map<string, string>>\n commandCounts(): Record<MemcachedCommandName, number>\n describe(): string\n close(): Promise<void>\n}\n\nfunction boundedInteger(value: number | undefined, fallback: number, min: number, max: number): number {\n if (value === undefined) return fallback\n if (!Number.isInteger(value) || value < min || value > max) {\n throw new MemcachedProtocolError('protocol_error', `Memcached client option must be an integer between ${min} and ${max}`)\n }\n return value\n}\n\n/**\n * Splits keys into batches whose pipelined command text stays within\n * `maxCommandBytes` and whose key count stays within `maxKeys`.\n */\nexport function planKeyBatches(keys: string[], lineBytes: (key: string) => number, maxCommandBytes: number, maxKeys: number): string[][] {\n const batches: string[][] = []\n let current: string[] = []\n let currentBytes = 0\n for (const key of keys) {\n const bytes = lineBytes(key)\n if (bytes > maxCommandBytes) {\n throw new MemcachedProtocolError('command_too_large', 'A single memcached key exceeds the command size limit')\n }\n if (current.length > 0 && (currentBytes + bytes > maxCommandBytes || current.length >= maxKeys)) {\n batches.push(current)\n current = []\n currentBytes = 0\n }\n current.push(key)\n currentBytes += bytes\n }\n if (current.length > 0) batches.push(current)\n return batches\n}\n\nconst META_GET_MANY_OVERHEAD = 'mg v c f k q\\r\\n'.length\nconst META_GET_MANY_TERMINATOR = 'mn\\r\\n'.length\nconst GETS_OVERHEAD = 'gets\\r\\n'.length\n\nexport function createMemcachedClient(options: MemcachedClientOptions): MemcachedClient {\n const transport = options.transport\n const poolSize = boundedInteger(options.poolSize, DEFAULT_POOL_SIZE, 1, 64)\n const connectTimeoutMs = boundedInteger(options.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS, 1, 120_000)\n const commandTimeoutMs = boundedInteger(options.commandTimeoutMs, DEFAULT_COMMAND_TIMEOUT_MS, 1, 120_000)\n const maxCommandBytes = boundedInteger(options.maxCommandBytes, MAX_COMMAND_BYTES, 256, MAX_COMMAND_BYTES)\n const maxKeysPerBatch = boundedInteger(options.maxKeysPerBatch, 512, 1, 4096)\n const slots: Array<Promise<MemcachedConnection> | null> = Array.from({ length: poolSize }, () => null)\n const counts: Record<MemcachedCommandName, number> = {\n mg: 0, ms: 0, md: 0, mn: 0, gets: 0, add: 0, cas: 0, version: 0, stats: 0,\n }\n let cursor = 0\n let closed = false\n\n const openSlot = (index: number): Promise<MemcachedConnection> => {\n const opening = MemcachedConnection.open(transport, { connectTimeoutMs, commandTimeoutMs }).then(\n (connection) => {\n if (closed) {\n connection.close()\n throw new MemcachedProtocolError('closed', 'Memcached client is closed')\n }\n return connection\n },\n (error: unknown) => {\n if (slots[index] === opening) slots[index] = null\n throw error\n },\n )\n slots[index] = opening\n return opening\n }\n\n const acquire = async (): Promise<MemcachedConnection> => {\n if (closed) throw new MemcachedProtocolError('closed', 'Memcached client is closed')\n const index = cursor\n cursor = (cursor + 1) % poolSize\n const slot = slots[index]\n if (slot) {\n const connection = await slot.catch(() => null)\n if (connection && connection.alive) return connection\n if (slots[index] !== slot) return acquire()\n }\n return openSlot(index)\n }\n\n const run = async <T>(name: MemcachedCommandName, build: () => EncodedCommand<T>): Promise<T> => {\n const command = build()\n const connection = await acquire()\n counts[name] += 1\n return connection.send(command.payload, command.parse)\n }\n\n const runBatches = async <T>(\n batches: string[][],\n execute: (batch: string[]) => Promise<Map<string, T>>,\n ): Promise<Map<string, T>> => {\n const merged = new Map<string, T>()\n for (let start = 0; start < batches.length; start += poolSize) {\n const wave = batches.slice(start, start + poolSize)\n const results = await Promise.all(wave.map(execute))\n for (const result of results) for (const [key, item] of result) merged.set(key, item)\n }\n return merged\n }\n\n return {\n metaGet: (key) => run('mg', () => metaGetCommand(key)),\n async metaGetMany(keys) {\n const unique = Array.from(new Set(keys))\n if (unique.length === 0) return new Map()\n const batches = planKeyBatches(\n unique,\n (key) => key.length + META_GET_MANY_OVERHEAD,\n maxCommandBytes - META_GET_MANY_TERMINATOR,\n maxKeysPerBatch,\n )\n return runBatches(batches, (batch) => run('mg', () => metaGetManyCommand(batch)))\n },\n metaSet: (key, value, setOptions) => run('ms', () => metaSetCommand(key, value, setOptions)),\n metaDelete: (key, deleteOptions) => run('md', () => metaDeleteCommand(key, deleteOptions)),\n async gets(keys) {\n const unique = Array.from(new Set(keys))\n if (unique.length === 0) return new Map()\n const batches = planKeyBatches(unique, (key) => key.length + 1, maxCommandBytes - GETS_OVERHEAD, maxKeysPerBatch)\n return runBatches(batches, (batch) => run('gets', () => getsCommand(batch)))\n },\n add: (key, value, storeOptions) => run('add', () => addCommand(key, value, storeOptions)),\n cas: (key, value, cas, storeOptions) => run('cas', () => casCommand(key, value, cas, storeOptions)),\n async noop() {\n await run('mn', () => noopCommand())\n },\n version: () => run('version', () => versionCommand()),\n stats: (group) => run('stats', () => statsCommand(group)),\n commandCounts: () => ({ ...counts }),\n describe: () => transport.describe(),\n async close() {\n if (closed) return\n closed = true\n const pending = slots.splice(0, slots.length)\n await Promise.all(pending.map(async (slot) => {\n if (!slot) return\n const connection = await slot.catch(() => null)\n connection?.close()\n }))\n },\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AAEvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AAEA,MAAM,oBAAoB,KAAK;AAC/B,MAAM,oBAAoB;AAC1B,MAAM,6BAA6B;AACnC,MAAM,6BAA6B;AA+B1C,SAAS,eAAe,OAA2B,UAAkB,KAAa,KAAqB;AACrG,MAAI,UAAU,OAAW,QAAO;AAChC,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,OAAO,QAAQ,KAAK;AAC1D,UAAM,IAAI,uBAAuB,kBAAkB,sDAAsD,GAAG,QAAQ,GAAG,EAAE;AAAA,EAC3H;AACA,SAAO;AACT;AAMO,SAAS,eAAe,MAAgB,WAAoC,iBAAyB,SAA6B;AACvI,QAAM,UAAsB,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