@checkstack/cache-memory-backend 0.3.20 → 0.3.22
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/CHANGELOG.md +27 -0
- package/package.json +6 -6
- package/src/memory-cache.test.ts +28 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @checkstack/cache-memory-backend
|
|
2
2
|
|
|
3
|
+
## 0.3.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [2e20792]
|
|
8
|
+
- Updated dependencies [2e20792]
|
|
9
|
+
- @checkstack/backend-api@0.26.0
|
|
10
|
+
- @checkstack/cache-memory-common@0.2.12
|
|
11
|
+
- @checkstack/cache-api@0.3.14
|
|
12
|
+
- @checkstack/common@0.17.0
|
|
13
|
+
|
|
14
|
+
## 0.3.21
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [8cad340]
|
|
19
|
+
- Updated dependencies [8cad340]
|
|
20
|
+
- Updated dependencies [8cad340]
|
|
21
|
+
- Updated dependencies [8cad340]
|
|
22
|
+
- Updated dependencies [8cad340]
|
|
23
|
+
- Updated dependencies [8cad340]
|
|
24
|
+
- Updated dependencies [8cad340]
|
|
25
|
+
- @checkstack/backend-api@0.25.0
|
|
26
|
+
- @checkstack/common@0.17.0
|
|
27
|
+
- @checkstack/cache-api@0.3.14
|
|
28
|
+
- @checkstack/cache-memory-common@0.2.11
|
|
29
|
+
|
|
3
30
|
## 0.3.20
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/cache-memory-backend",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"checkstack": {
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"pack": "bunx @checkstack/scripts plugin-pack"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@checkstack/backend-api": "0.
|
|
21
|
-
"@checkstack/cache-api": "0.3.
|
|
22
|
-
"@checkstack/cache-memory-common": "0.2.
|
|
23
|
-
"@checkstack/common": "0.
|
|
20
|
+
"@checkstack/backend-api": "0.26.0",
|
|
21
|
+
"@checkstack/cache-api": "0.3.14",
|
|
22
|
+
"@checkstack/cache-memory-common": "0.2.12",
|
|
23
|
+
"@checkstack/common": "0.17.0",
|
|
24
24
|
"zod": "^4.2.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/bun": "latest",
|
|
28
28
|
"@checkstack/tsconfig": "0.0.7",
|
|
29
|
-
"@checkstack/scripts": "0.6.
|
|
29
|
+
"@checkstack/scripts": "0.6.4"
|
|
30
30
|
},
|
|
31
31
|
"description": "Checkstack cache-memory-backend plugin",
|
|
32
32
|
"author": {
|
package/src/memory-cache.test.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
it,
|
|
4
|
+
expect,
|
|
5
|
+
afterEach,
|
|
6
|
+
beforeEach,
|
|
7
|
+
jest,
|
|
8
|
+
setSystemTime,
|
|
9
|
+
} from "bun:test";
|
|
2
10
|
import { InMemoryCache } from "./memory-cache";
|
|
3
11
|
|
|
4
12
|
describe("InMemoryCache", () => {
|
|
5
13
|
const caches: InMemoryCache[] = [];
|
|
6
14
|
|
|
15
|
+
// Fake timers make TTL expiry and the periodic sweep deterministic: the cache
|
|
16
|
+
// stores `expiresAt = Date.now() + ttlMs` and evicts when `Date.now()` passes
|
|
17
|
+
// it, and the sweep runs on a `setInterval`. Advancing the fake clock crosses
|
|
18
|
+
// those boundaries exactly, instead of sleeping real milliseconds and hoping.
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.useFakeTimers();
|
|
21
|
+
setSystemTime(new Date("2026-01-18T10:00:00Z"));
|
|
22
|
+
});
|
|
23
|
+
|
|
7
24
|
function createCache({
|
|
8
25
|
maxEntries = 100,
|
|
9
26
|
sweepIntervalMs = 0,
|
|
@@ -18,6 +35,7 @@ describe("InMemoryCache", () => {
|
|
|
18
35
|
cache.stop();
|
|
19
36
|
}
|
|
20
37
|
caches.length = 0;
|
|
38
|
+
jest.useRealTimers();
|
|
21
39
|
});
|
|
22
40
|
|
|
23
41
|
describe("basic operations", () => {
|
|
@@ -91,15 +109,15 @@ describe("InMemoryCache", () => {
|
|
|
91
109
|
const cache = createCache();
|
|
92
110
|
// Set with 1ms TTL
|
|
93
111
|
await cache.set("key", "value", 1);
|
|
94
|
-
//
|
|
95
|
-
|
|
112
|
+
// Advance past expiry
|
|
113
|
+
jest.advanceTimersByTime(10);
|
|
96
114
|
expect(await cache.get("key")).toBeUndefined();
|
|
97
115
|
});
|
|
98
116
|
|
|
99
117
|
it("has returns false after TTL expires", async () => {
|
|
100
118
|
const cache = createCache();
|
|
101
119
|
await cache.set("key", "value", 1);
|
|
102
|
-
|
|
120
|
+
jest.advanceTimersByTime(10);
|
|
103
121
|
expect(await cache.has("key")).toBe(false);
|
|
104
122
|
});
|
|
105
123
|
|
|
@@ -115,7 +133,7 @@ describe("InMemoryCache", () => {
|
|
|
115
133
|
await cache.set("key", "v1", 1);
|
|
116
134
|
// Overwrite with no TTL
|
|
117
135
|
await cache.set("key", "v2");
|
|
118
|
-
|
|
136
|
+
jest.advanceTimersByTime(10);
|
|
119
137
|
// Should still be available since new entry has no TTL
|
|
120
138
|
expect(await cache.get<string>("key")).toBe("v2");
|
|
121
139
|
});
|
|
@@ -180,7 +198,7 @@ describe("InMemoryCache", () => {
|
|
|
180
198
|
const cache = createCache();
|
|
181
199
|
await cache.set("scope:a", "x", 1);
|
|
182
200
|
await cache.set("scope:b", "y");
|
|
183
|
-
|
|
201
|
+
jest.advanceTimersByTime(10);
|
|
184
202
|
|
|
185
203
|
// Both keys are still in the underlying map (passive eviction);
|
|
186
204
|
// deleteByPrefix sweeps both regardless.
|
|
@@ -197,8 +215,8 @@ describe("InMemoryCache", () => {
|
|
|
197
215
|
await cache.set("expires", "value", 1);
|
|
198
216
|
await cache.set("stays", "value");
|
|
199
217
|
|
|
200
|
-
//
|
|
201
|
-
|
|
218
|
+
// Advance past several sweep intervals so the periodic sweep runs.
|
|
219
|
+
jest.advanceTimersByTime(50);
|
|
202
220
|
|
|
203
221
|
// "expires" should have been swept
|
|
204
222
|
expect(cache.size).toBe(1);
|
|
@@ -212,7 +230,7 @@ describe("InMemoryCache", () => {
|
|
|
212
230
|
cache.stop();
|
|
213
231
|
// Should not throw or continue sweeping
|
|
214
232
|
await cache.set("key", "value", 1);
|
|
215
|
-
|
|
233
|
+
jest.advanceTimersByTime(50);
|
|
216
234
|
// Entry may or may not be expired (passive eviction), but no crash
|
|
217
235
|
});
|
|
218
236
|
});
|
|
@@ -277,7 +295,7 @@ describe("InMemoryCache", () => {
|
|
|
277
295
|
const cache = createCache();
|
|
278
296
|
await cache.set("k", "value", 10);
|
|
279
297
|
expect((await cache.getStats()).sizeBytes!).toBeGreaterThan(0);
|
|
280
|
-
|
|
298
|
+
jest.advanceTimersByTime(30);
|
|
281
299
|
// Passive eviction via get
|
|
282
300
|
expect(await cache.get("k")).toBeUndefined();
|
|
283
301
|
expect((await cache.getStats()).sizeBytes).toBe(0);
|