@c9up/echo 0.2.3 → 0.2.4
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/dist/CacheManager.d.ts +2 -0
- package/dist/CacheManager.d.ts.map +1 -1
- package/dist/CacheManager.js +92 -32
- package/dist/CacheManager.js.map +1 -1
- package/dist/EchoProvider.d.ts.map +1 -1
- package/dist/EchoProvider.js +32 -3
- package/dist/EchoProvider.js.map +1 -1
- package/dist/StoreManager.d.ts +28 -9
- package/dist/StoreManager.d.ts.map +1 -1
- package/dist/StoreManager.js +42 -18
- package/dist/StoreManager.js.map +1 -1
- package/dist/bytes.d.ts +13 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +35 -0
- package/dist/bytes.js.map +1 -0
- package/dist/claim.d.ts +15 -0
- package/dist/claim.d.ts.map +1 -0
- package/dist/claim.js +10 -0
- package/dist/claim.js.map +1 -0
- package/dist/configure.d.ts +1 -0
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +3 -0
- package/dist/configure.js.map +1 -1
- package/dist/console/cacheClear.d.ts +13 -0
- package/dist/console/cacheClear.d.ts.map +1 -0
- package/dist/console/cacheClear.js +69 -0
- package/dist/console/cacheClear.js.map +1 -0
- package/dist/console/cacheDelete.d.ts +11 -0
- package/dist/console/cacheDelete.d.ts.map +1 -0
- package/dist/console/cacheDelete.js +42 -0
- package/dist/console/cacheDelete.js.map +1 -0
- package/dist/console/cachePrune.d.ts +9 -0
- package/dist/console/cachePrune.d.ts.map +1 -0
- package/dist/console/cachePrune.js +35 -0
- package/dist/console/cachePrune.js.map +1 -0
- package/dist/console/contract.d.ts +64 -0
- package/dist/console/contract.d.ts.map +1 -0
- package/dist/console/contract.js +32 -0
- package/dist/console/contract.js.map +1 -0
- package/dist/console/index.d.ts +25 -0
- package/dist/console/index.d.ts.map +1 -0
- package/dist/console/index.js +38 -0
- package/dist/console/index.js.map +1 -0
- package/dist/console/store.d.ts +14 -0
- package/dist/console/store.d.ts.map +1 -0
- package/dist/console/store.js +35 -0
- package/dist/console/store.js.map +1 -0
- package/dist/drivers/MemoryDriver.d.ts +36 -1
- package/dist/drivers/MemoryDriver.d.ts.map +1 -1
- package/dist/drivers/MemoryDriver.js +157 -62
- package/dist/drivers/MemoryDriver.js.map +1 -1
- package/dist/drivers/RedisDriver.d.ts +13 -8
- package/dist/drivers/RedisDriver.d.ts.map +1 -1
- package/dist/drivers/RedisDriver.js +171 -94
- package/dist/drivers/RedisDriver.js.map +1 -1
- package/dist/drivers/TieredDriver.d.ts +42 -0
- package/dist/drivers/TieredDriver.d.ts.map +1 -1
- package/dist/drivers/TieredDriver.js +114 -9
- package/dist/drivers/TieredDriver.js.map +1 -1
- package/dist/duration.d.ts +13 -3
- package/dist/duration.d.ts.map +1 -1
- package/dist/duration.js +22 -7
- package/dist/duration.js.map +1 -1
- package/dist/errors.d.ts +60 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +81 -6
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/quasar.d.ts +1 -1
- package/dist/quasar.d.ts.map +1 -1
- package/dist/quasar.js +27 -6
- package/dist/quasar.js.map +1 -1
- package/dist/services/main.d.ts +1 -1
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +22 -5
- package/dist/services/main.js.map +1 -1
- package/dist/types.d.ts +12 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/vendor/quasarConnection.d.ts +26 -3
- package/dist/vendor/quasarConnection.d.ts.map +1 -1
- package/dist/vendor/quasarConnection.js +44 -23
- package/dist/vendor/quasarConnection.js.map +1 -1
- package/package.json +5 -1
- package/src/CacheManager.ts +117 -41
- package/src/EchoProvider.ts +45 -4
- package/src/StoreManager.ts +86 -31
- package/src/bytes.ts +38 -0
- package/src/claim.ts +22 -0
- package/src/configure.ts +4 -0
- package/src/console/cacheClear.ts +96 -0
- package/src/console/cacheDelete.ts +65 -0
- package/src/console/cachePrune.ts +57 -0
- package/src/console/contract.ts +93 -0
- package/src/console/index.ts +61 -0
- package/src/console/store.ts +47 -0
- package/src/drivers/MemoryDriver.ts +205 -60
- package/src/drivers/RedisDriver.ts +205 -101
- package/src/drivers/TieredDriver.ts +169 -9
- package/src/duration.ts +28 -7
- package/src/errors.ts +103 -6
- package/src/index.ts +17 -3
- package/src/quasar.ts +44 -8
- package/src/services/main.ts +26 -8
- package/src/types.ts +13 -2
- package/src/vendor/quasarConnection.ts +84 -22
|
@@ -4,9 +4,42 @@
|
|
|
4
4
|
* as the L1 tier of {@link TieredDriver}.
|
|
5
5
|
*/
|
|
6
6
|
import type { CacheEntry, DriverSetOptions, TaggableDriver } from "../types.js";
|
|
7
|
+
export interface MemoryDriverOptions {
|
|
8
|
+
/** How often expired entries are swept, in milliseconds (default 60 000). */
|
|
9
|
+
sweepIntervalMs?: number;
|
|
10
|
+
/**
|
|
11
|
+
* How many entries the store holds before it evicts the least recently
|
|
12
|
+
* used. Default 1000, as upstream; `0` or `Infinity` for no ceiling.
|
|
13
|
+
*/
|
|
14
|
+
maxItems?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Total size of the stored values, in bytes or as `'10mb'`; past it the
|
|
17
|
+
* least recently used entries go. Needs `serialize`, since it measures
|
|
18
|
+
* the JSON.
|
|
19
|
+
*/
|
|
20
|
+
maxSize?: number | string;
|
|
21
|
+
/**
|
|
22
|
+
* Largest single value, in bytes or as `'1mb'`. A bigger one is not
|
|
23
|
+
* stored, and the key's previous value goes with it. Defaults to
|
|
24
|
+
* `maxSize` when that is set. Needs `serialize`.
|
|
25
|
+
*/
|
|
26
|
+
maxEntrySize?: number | string;
|
|
27
|
+
/**
|
|
28
|
+
* Store values as JSON and hand out a fresh copy on every read (default).
|
|
29
|
+
*
|
|
30
|
+
* `false` keeps the caller's object and returns that same reference, which
|
|
31
|
+
* is faster and keeps class instances, Dates and Maps intact — but any
|
|
32
|
+
* reader that mutates what it got rewrites the value for every later one.
|
|
33
|
+
*/
|
|
34
|
+
serialize?: boolean;
|
|
35
|
+
}
|
|
7
36
|
export declare class MemoryDriver implements TaggableDriver {
|
|
8
37
|
#private;
|
|
9
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @param options the options, or the sweep interval in milliseconds (the
|
|
40
|
+
* original positional form, kept with `maxItems` beside it).
|
|
41
|
+
*/
|
|
42
|
+
constructor(options?: MemoryDriverOptions | number, maxItems?: number);
|
|
10
43
|
/**
|
|
11
44
|
* Drop expired entries now, without waiting for the sweep (bentocache
|
|
12
45
|
* `prune`). Useful before measuring size, or in a test that must not depend
|
|
@@ -23,6 +56,8 @@ export declare class MemoryDriver implements TaggableDriver {
|
|
|
23
56
|
getEntry<T = unknown>(key: string): Promise<CacheEntry<T> | null>;
|
|
24
57
|
/** Synchronous read used by both `get` and `getEntry` (and by TieredDriver's L1 fast path). */
|
|
25
58
|
getEntrySync<T = unknown>(key: string): CacheEntry<T> | null;
|
|
59
|
+
/** How many tags the index holds — what bounds its memory, for diagnostics. */
|
|
60
|
+
tagCount(): number;
|
|
26
61
|
set(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
|
|
27
62
|
setEntry(key: string, value: unknown, options: DriverSetOptions): Promise<void>;
|
|
28
63
|
delete(key: string): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryDriver.d.ts","sourceRoot":"","sources":["../../src/drivers/MemoryDriver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"MemoryDriver.d.ts","sourceRoot":"","sources":["../../src/drivers/MemoryDriver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IACnC,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAA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AM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxC,qEAAqE;IAC/D,WAAW,CAChB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EAAE,EACd,UAAU,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAIhB,gEAAgE;IAC1D,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAehD,gDAAgD;IAC1C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
|
|
@@ -3,48 +3,103 @@
|
|
|
3
3
|
* and tag support. Suitable for development and single-process deployments, and
|
|
4
4
|
* as the L1 tier of {@link TieredDriver}.
|
|
5
5
|
*/
|
|
6
|
+
import { parseBytes } from "../bytes.js";
|
|
7
|
+
import { claimed, hasUnref } from "../claim.js";
|
|
8
|
+
import { checkTtlSeconds } from "../duration.js";
|
|
9
|
+
import { EchoError, UndefinedValueError } from "../errors.js";
|
|
10
|
+
/** The JSON a value is stored as; refused when JSON cannot carry it. */
|
|
11
|
+
function toJson(value) {
|
|
12
|
+
const json = JSON.stringify(value);
|
|
13
|
+
if (json === undefined) {
|
|
14
|
+
throw new EchoError("E_ECHO_UNSERIALIZABLE_VALUE", "Echo: the memory driver stores values as JSON, and this one has no JSON form — pass `serialize: false` to keep it as is");
|
|
15
|
+
}
|
|
16
|
+
return json;
|
|
17
|
+
}
|
|
6
18
|
export class MemoryDriver {
|
|
7
19
|
#store = new Map();
|
|
8
20
|
#tagIndex = new Map();
|
|
9
21
|
#sweepInterval;
|
|
10
22
|
/**
|
|
11
|
-
* How many entries this driver holds before it
|
|
23
|
+
* How many entries this driver holds before it evicts.
|
|
12
24
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* genuinely wants no ceiling.
|
|
25
|
+
* 1000 unless told otherwise, as upstream's LRU. It had no ceiling by
|
|
26
|
+
* default, so a cache keyed by anything a user controls — an id, a search
|
|
27
|
+
* term — grew until the process ran out of memory. `0` is an explicit "no
|
|
28
|
+
* ceiling".
|
|
18
29
|
*/
|
|
19
30
|
#maxItems;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
/** Byte bound on all values together; `0` for none. */
|
|
32
|
+
#maxSize;
|
|
33
|
+
/** Byte bound on one value; `0` for none. */
|
|
34
|
+
#maxEntrySize;
|
|
35
|
+
/** Bytes held, kept in step with every write and removal. */
|
|
36
|
+
#size = 0;
|
|
37
|
+
/**
|
|
38
|
+
* Whether values go in as JSON and come out as a copy.
|
|
39
|
+
*
|
|
40
|
+
* On by default, as upstream serializes its L1 by default: the driver kept
|
|
41
|
+
* the caller's object and returned that same reference, so a request that
|
|
42
|
+
* mutated what it read — a cached permission set, say — changed it for
|
|
43
|
+
* every later reader. JSON is also what the Redis driver stores, so a
|
|
44
|
+
* value reads back the same in development and in production.
|
|
45
|
+
*/
|
|
46
|
+
#serialize;
|
|
47
|
+
/**
|
|
48
|
+
* @param options the options, or the sweep interval in milliseconds (the
|
|
49
|
+
* original positional form, kept with `maxItems` beside it).
|
|
50
|
+
*/
|
|
51
|
+
constructor(options = {}, maxItems) {
|
|
52
|
+
const config = typeof options === "number"
|
|
53
|
+
? { sweepIntervalMs: options, maxItems }
|
|
54
|
+
: options;
|
|
55
|
+
const ceiling = config.maxItems ?? 1000;
|
|
56
|
+
if (Number.isNaN(ceiling) || ceiling < 0) {
|
|
57
|
+
throw new EchoError("E_ECHO_INVALID_CONFIG", `Echo: maxItems must be a count, 0 or Infinity for no ceiling — got ${String(ceiling)}`);
|
|
26
58
|
}
|
|
59
|
+
this.#maxItems = Number.isFinite(ceiling) ? ceiling : 0;
|
|
60
|
+
this.#serialize = config.serialize ?? true;
|
|
61
|
+
if (!this.#serialize &&
|
|
62
|
+
(config.maxSize !== undefined || config.maxEntrySize !== undefined)) {
|
|
63
|
+
// What it would measure is the JSON, and a driver keeping
|
|
64
|
+
// references has none. Upstream refuses the same combination.
|
|
65
|
+
throw new EchoError("E_ECHO_INVALID_CONFIG", "Echo: maxSize and maxEntrySize measure the stored JSON, so they need `serialize` — drop `serialize: false` or the byte bound");
|
|
66
|
+
}
|
|
67
|
+
this.#maxSize =
|
|
68
|
+
config.maxSize === undefined ? 0 : parseBytes(config.maxSize, "maxSize");
|
|
69
|
+
this.#maxEntrySize =
|
|
70
|
+
config.maxEntrySize === undefined
|
|
71
|
+
? this.#maxSize
|
|
72
|
+
: parseBytes(config.maxEntrySize, "maxEntrySize");
|
|
73
|
+
this.#sweepInterval = setInterval(() => this.#sweep(), config.sweepIntervalMs ?? 60_000);
|
|
74
|
+
// The sweep is housekeeping, not a reason for the process to stay up.
|
|
75
|
+
if (hasUnref(this.#sweepInterval))
|
|
76
|
+
this.#sweepInterval.unref();
|
|
77
|
+
}
|
|
78
|
+
#fits() {
|
|
79
|
+
return ((this.#maxItems === 0 || this.#store.size <= this.#maxItems) &&
|
|
80
|
+
(this.#maxSize === 0 || this.#size <= this.#maxSize));
|
|
27
81
|
}
|
|
28
82
|
/**
|
|
29
|
-
* Drop
|
|
83
|
+
* Drop entries until the store fits under its ceilings.
|
|
30
84
|
*
|
|
31
85
|
* Expired ones go first — evicting a live entry while a dead one sits in
|
|
32
86
|
* the map would throw away a value someone still wants. Only if that is not
|
|
33
|
-
* enough does it take the least recently
|
|
87
|
+
* enough does it take the least recently used: the Map's order, since a
|
|
88
|
+
* read moves its key to the end as a write does.
|
|
34
89
|
*/
|
|
35
90
|
#enforceCeiling() {
|
|
36
|
-
if (this.#
|
|
91
|
+
if (this.#fits())
|
|
37
92
|
return;
|
|
38
93
|
const now = Date.now();
|
|
39
94
|
for (const [key, entry] of this.#store) {
|
|
40
|
-
if (this.#
|
|
95
|
+
if (this.#fits())
|
|
41
96
|
return;
|
|
42
97
|
if (entry.staleUntil > 0 && entry.staleUntil < now) {
|
|
43
98
|
this.#evict(key, entry);
|
|
44
99
|
}
|
|
45
100
|
}
|
|
46
101
|
for (const [key, entry] of this.#store) {
|
|
47
|
-
if (this.#
|
|
102
|
+
if (this.#fits())
|
|
48
103
|
return;
|
|
49
104
|
this.#evict(key, entry);
|
|
50
105
|
}
|
|
@@ -95,8 +150,20 @@ export class MemoryDriver {
|
|
|
95
150
|
this.#evict(key, entry);
|
|
96
151
|
return null;
|
|
97
152
|
}
|
|
153
|
+
// Least recently USED, not written: a read moves the key to the end of
|
|
154
|
+
// the eviction order. Without it the hottest key was the first to go.
|
|
155
|
+
this.#store.delete(key);
|
|
156
|
+
this.#store.set(key, entry);
|
|
98
157
|
const stale = entry.expiresAt > 0 && entry.expiresAt < now;
|
|
99
|
-
|
|
158
|
+
const value = this.#serialize && typeof entry.value === "string"
|
|
159
|
+
? JSON.parse(entry.value)
|
|
160
|
+
: entry.value;
|
|
161
|
+
return {
|
|
162
|
+
value: claimed(value),
|
|
163
|
+
stale,
|
|
164
|
+
expiresAt: entry.expiresAt,
|
|
165
|
+
tags: [...entry.tags],
|
|
166
|
+
};
|
|
100
167
|
}
|
|
101
168
|
/**
|
|
102
169
|
* Delete an entry AND scrub its tag-index refs. TTL/grace expiry (sweep +
|
|
@@ -105,24 +172,64 @@ export class MemoryDriver {
|
|
|
105
172
|
* into a wrong-purge under deleteByTag (audit 2026-06-13).
|
|
106
173
|
*/
|
|
107
174
|
#evict(key, entry) {
|
|
108
|
-
|
|
109
|
-
this.#tagIndex.get(tag)?.delete(key);
|
|
175
|
+
this.#untag(key, entry.tags);
|
|
110
176
|
this.#store.delete(key);
|
|
177
|
+
this.#size -= entry.size;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Take `key` out of each tag's set, and drop a set it leaves empty.
|
|
181
|
+
*
|
|
182
|
+
* Emptied sets were kept, so per-user or per-id tags grew the index by one
|
|
183
|
+
* set per entry ever written: a store capped at ten entries held hundreds
|
|
184
|
+
* of megabytes of empty sets.
|
|
185
|
+
*/
|
|
186
|
+
#untag(key, tags) {
|
|
187
|
+
for (const tag of tags) {
|
|
188
|
+
const keys = this.#tagIndex.get(tag);
|
|
189
|
+
if (keys === undefined)
|
|
190
|
+
continue;
|
|
191
|
+
keys.delete(key);
|
|
192
|
+
if (keys.size === 0)
|
|
193
|
+
this.#tagIndex.delete(tag);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** How many tags the index holds — what bounds its memory, for diagnostics. */
|
|
197
|
+
tagCount() {
|
|
198
|
+
return this.#tagIndex.size;
|
|
111
199
|
}
|
|
112
200
|
#write(key, value, ttlSeconds, graceSeconds, tags, expiresAtOverride) {
|
|
113
201
|
if (value === null || value === undefined) {
|
|
114
|
-
throw new
|
|
202
|
+
throw new UndefinedValueError();
|
|
203
|
+
}
|
|
204
|
+
// Before anything is touched: a value JSON cannot carry must leave the
|
|
205
|
+
// previous entry and its tags exactly as they were.
|
|
206
|
+
const stored = this.#serialize ? toJson(value) : value;
|
|
207
|
+
const size = typeof stored === "string" ? Buffer.byteLength(stored) : 0;
|
|
208
|
+
if (this.#maxEntrySize > 0 && size > this.#maxEntrySize) {
|
|
209
|
+
// Too big to keep. The previous value goes too, as upstream's LRU
|
|
210
|
+
// does: a skipped write must not leave an older value served.
|
|
211
|
+
this.#deleteEntry(key);
|
|
212
|
+
return;
|
|
115
213
|
}
|
|
116
214
|
const now = Date.now();
|
|
117
|
-
const
|
|
215
|
+
const ttl = ttlSeconds === undefined ? 0 : checkTtlSeconds(ttlSeconds);
|
|
216
|
+
const graceMs = graceSeconds > 0 ? graceSeconds * 1000 : 0;
|
|
217
|
+
if (expiresAtOverride === undefined && ttl < 0 && graceMs === 0) {
|
|
218
|
+
// Already expired, and no grace to keep a stale copy for: nothing
|
|
219
|
+
// to store, and the previous value must not survive it.
|
|
220
|
+
this.#deleteEntry(key);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
118
223
|
// An absolute `expiresAtOverride` (e.g. `expire()` marking stale-now) wins
|
|
119
|
-
// over the ttl-derived expiry; a past value makes the entry immediately
|
|
224
|
+
// over the ttl-derived expiry; a past value makes the entry immediately
|
|
225
|
+
// stale. So does a negative TTL — it never reads as "no expiry".
|
|
120
226
|
const expiresAt = expiresAtOverride !== undefined
|
|
121
227
|
? expiresAtOverride
|
|
122
|
-
:
|
|
123
|
-
? now
|
|
124
|
-
: 0
|
|
125
|
-
|
|
228
|
+
: ttl < 0
|
|
229
|
+
? now - 1
|
|
230
|
+
: ttl > 0
|
|
231
|
+
? now + ttl * 1000
|
|
232
|
+
: 0;
|
|
126
233
|
// A never-expiring entry never goes stale either; otherwise grace extends
|
|
127
234
|
// physical retention past the logical expiry. Measure grace from the LATER
|
|
128
235
|
// of the expiry and now, so an already-past expiry still survives its grace.
|
|
@@ -131,15 +238,17 @@ export class MemoryDriver {
|
|
|
131
238
|
// its old tag-index refs, or a later deleteByTag could purge this fresh
|
|
132
239
|
// value (audit 2026-05-22 F3).
|
|
133
240
|
const prev = this.#store.get(key);
|
|
134
|
-
if (prev !== undefined)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
241
|
+
if (prev !== undefined)
|
|
242
|
+
this.#evict(key, prev);
|
|
243
|
+
// Inserted last, so it is the most recently used.
|
|
244
|
+
this.#store.set(key, {
|
|
245
|
+
value: stored,
|
|
246
|
+
expiresAt,
|
|
247
|
+
staleUntil,
|
|
248
|
+
tags,
|
|
249
|
+
size,
|
|
250
|
+
});
|
|
251
|
+
this.#size += size;
|
|
143
252
|
this.#enforceCeiling();
|
|
144
253
|
for (const tag of tags) {
|
|
145
254
|
let set = this.#tagIndex.get(tag);
|
|
@@ -157,32 +266,25 @@ export class MemoryDriver {
|
|
|
157
266
|
this.#write(key, value, options.ttlSeconds, options.graceSeconds ?? 0, options.tags ?? [], options.expiresAt);
|
|
158
267
|
}
|
|
159
268
|
async delete(key) {
|
|
269
|
+
return this.#deleteEntry(key);
|
|
270
|
+
}
|
|
271
|
+
#deleteEntry(key) {
|
|
160
272
|
const entry = this.#store.get(key);
|
|
161
|
-
if (entry)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return this.#store.delete(key);
|
|
273
|
+
if (entry === undefined)
|
|
274
|
+
return false;
|
|
275
|
+
this.#evict(key, entry);
|
|
276
|
+
return true;
|
|
167
277
|
}
|
|
168
278
|
async flush(prefix) {
|
|
169
279
|
if (prefix === undefined) {
|
|
170
280
|
this.#store.clear();
|
|
171
281
|
this.#tagIndex.clear();
|
|
282
|
+
this.#size = 0;
|
|
172
283
|
return;
|
|
173
284
|
}
|
|
174
|
-
for (const key of [...this.#store
|
|
285
|
+
for (const [key, entry] of [...this.#store]) {
|
|
175
286
|
if (key.startsWith(prefix))
|
|
176
|
-
this.#
|
|
177
|
-
}
|
|
178
|
-
// The tag index points at keys; the ones that are gone go with them.
|
|
179
|
-
for (const [tag, keys] of [...this.#tagIndex.entries()]) {
|
|
180
|
-
for (const key of [...keys]) {
|
|
181
|
-
if (key.startsWith(prefix))
|
|
182
|
-
keys.delete(key);
|
|
183
|
-
}
|
|
184
|
-
if (keys.size === 0)
|
|
185
|
-
this.#tagIndex.delete(tag);
|
|
287
|
+
this.#evict(key, entry);
|
|
186
288
|
}
|
|
187
289
|
}
|
|
188
290
|
async has(key) {
|
|
@@ -205,15 +307,8 @@ export class MemoryDriver {
|
|
|
205
307
|
toDelete.add(key);
|
|
206
308
|
}
|
|
207
309
|
}
|
|
208
|
-
for (const key of toDelete)
|
|
209
|
-
|
|
210
|
-
if (entry) {
|
|
211
|
-
for (const t of entry.tags) {
|
|
212
|
-
this.#tagIndex.get(t)?.delete(key);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
this.#store.delete(key);
|
|
216
|
-
}
|
|
310
|
+
for (const key of toDelete)
|
|
311
|
+
this.#deleteEntry(key);
|
|
217
312
|
for (const tag of tags)
|
|
218
313
|
this.#tagIndex.delete(tag);
|
|
219
314
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryDriver.js","sourceRoot":"","sources":["../../src/drivers/MemoryDriver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"MemoryDriver.js","sourceRoot":"","sources":["../../src/drivers/MemoryDriver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AA6C9D,wEAAwE;AACxE,SAAS,MAAM,CAAC,KAAc;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,SAAS,CAClB,6BAA6B,EAC7B,yHAAyH,CACzH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,OAAO,YAAY;IACxB,MAAM,GAA6B,IAAI,GAAG,EAAE,CAAC;IAC7C,SAAS,GAA6B,IAAI,GAAG,EAAE,CAAC;IAChD,cAAc,CAAiC;IAC/C;;;;;;;OAOG;IACM,SAAS,CAAS;IAC3B,uDAAuD;IAC9C,QAAQ,CAAS;IAC1B,6CAA6C;IACpC,aAAa,CAAS;IAC/B,6DAA6D;IAC7D,KAAK,GAAG,CAAC,CAAC;IACV;;;;;;;;OAQG;IACM,UAAU,CAAU;IAE7B;;;OAGG;IACH,YAAY,UAAwC,EAAE,EAAE,QAAiB;QACxE,MA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Requires a Redis client
|
|
7
|
-
*
|
|
6
|
+
* Requires a Redis client implementing the minimal interface below, which a
|
|
7
|
+
* raw ioredis client satisfies.
|
|
8
8
|
*
|
|
9
|
-
* STORAGE FORMAT
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* STORAGE FORMAT: values live at `<prefix>v:<key>` as a JSON envelope
|
|
10
|
+
* `{ "v": <value>, "e": <logicalExpiryEpochMs> }`; tag sets at `<prefix>t:<tag>`
|
|
11
|
+
* and per-key reverse indexes at `<prefix>m:<key>`. The physical Redis TTL
|
|
12
|
+
* covers `ttl + grace` so a logically-expired value survives for the grace
|
|
13
|
+
* window; `e` records the logical expiry so reads can flag it stale.
|
|
13
14
|
*/
|
|
14
15
|
import type { CacheEntry, DriverSetOptions, TaggableDriver } from "../types.js";
|
|
15
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Minimal Redis client interface, in ioredis' shape — a raw ioredis client
|
|
18
|
+
* satisfies it as is.
|
|
19
|
+
*/
|
|
16
20
|
export interface RedisClient {
|
|
17
21
|
get(key: string): Promise<string | null>;
|
|
18
22
|
set(key: string, value: string, ...args: unknown[]): Promise<unknown>;
|
|
19
|
-
|
|
23
|
+
/** Variadic, as ioredis declares it: a raw client then typechecks. */
|
|
24
|
+
del(...keys: string[]): Promise<number>;
|
|
20
25
|
exists(key: string): Promise<number>;
|
|
21
26
|
keys(pattern: string): Promise<string[]>;
|
|
22
27
|
sadd(key: string, ...members: string[]): Promise<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisDriver.d.ts","sourceRoot":"","sources":["../../src/drivers/RedisDriver.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"RedisDriver.d.ts","sourceRoot":"","sources":["../../src/drivers/RedisDriver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,M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