@geekmidas/cache 0.0.4 → 0.0.6
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/__tests__/cache.spec.cjs +32 -32
- package/dist/__tests__/cache.spec.mjs +19 -18
- package/dist/__tests__/integration.spec.cjs +46 -46
- package/dist/__tests__/integration.spec.mjs +27 -26
- package/dist/__tests__/memory.spec.cjs +46 -46
- package/dist/__tests__/memory.spec.mjs +24 -23
- package/dist/__tests__/upstash.spec.cjs +50 -51
- package/dist/__tests__/upstash.spec.mjs +23 -23
- package/dist/{chunk-CUT6urMc.cjs → chunk-DWy1uDak.cjs} +9 -0
- package/dist/expo.cjs +36 -0
- package/dist/expo.d.cts +12 -0
- package/dist/expo.d.mts +12 -0
- package/dist/expo.mjs +35 -0
- package/dist/{index-BPnJ3lrS.d.mts → index-B6eF5Yxi.d.cts} +9 -1
- package/dist/{index-q3xYn8_0.d.cts → index-Bv61mxVT.d.mts} +9 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -0
- package/dist/magic-string.es-CBih0MJw.mjs +1014 -0
- package/dist/magic-string.es-KiPEzMtt.cjs +1015 -0
- package/dist/memory-Csy6J-Ak.cjs +39 -0
- package/dist/memory-QDTnSEX5.mjs +33 -0
- package/dist/memory.cjs +2 -1
- package/dist/memory.d.cts +4 -2
- package/dist/memory.d.mts +4 -2
- package/dist/memory.mjs +2 -1
- package/dist/src-C7d6HaTp.cjs +19 -0
- package/dist/src-DVpoP03o.mjs +13 -0
- package/dist/{upstash-CTY-M8vR.mjs → upstash-CXy_duOa.mjs} +5 -0
- package/dist/{upstash-0RolGx7m.cjs → upstash-u8Hs4sZG.cjs} +6 -1
- package/dist/upstash.cjs +1 -1
- package/dist/upstash.d.cts +2 -1
- package/dist/upstash.d.mts +2 -1
- package/dist/upstash.mjs +1 -1
- package/dist/vi.bdSIJ99Y-B-qkABPq.cjs +14955 -0
- package/dist/vi.bdSIJ99Y-CB5havZF.mjs +14951 -0
- package/package.json +11 -3
- package/src/expo.ts +51 -0
- package/src/index.ts +25 -0
- package/src/memory.ts +22 -2
- package/src/upstash.ts +10 -0
- package/tsdown.config.ts +5 -0
- package/dist/memory-NQi0XmZ2.mjs +0 -16
- package/dist/memory-n6Iosq6J.cjs +0 -22
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
const require_memory = require('../memory-
|
|
3
|
-
const require_upstash = require('../upstash-
|
|
4
|
-
const
|
|
1
|
+
require('../src-C7d6HaTp.cjs');
|
|
2
|
+
const require_memory = require('../memory-Csy6J-Ak.cjs');
|
|
3
|
+
const require_upstash = require('../upstash-u8Hs4sZG.cjs');
|
|
4
|
+
const require_vi_bdSIJ99Y = require('../vi.bdSIJ99Y-B-qkABPq.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/__tests__/cache.spec.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
require_vi_bdSIJ99Y.describe("Cache Interface", () => {
|
|
8
|
+
require_vi_bdSIJ99Y.describe("interface compliance", () => {
|
|
9
|
+
require_vi_bdSIJ99Y.it("InMemoryCache should implement Cache interface", () => {
|
|
10
10
|
const cache = new require_memory.InMemoryCache();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
require_vi_bdSIJ99Y.globalExpect(typeof cache.get).toBe("function");
|
|
12
|
+
require_vi_bdSIJ99Y.globalExpect(typeof cache.set).toBe("function");
|
|
13
|
+
require_vi_bdSIJ99Y.globalExpect(typeof cache.delete).toBe("function");
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
require_vi_bdSIJ99Y.it("UpstashCache should implement Cache interface", () => {
|
|
16
16
|
const cache = new require_upstash.UpstashCache("http://localhost:8079", "example_token");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
require_vi_bdSIJ99Y.globalExpect(typeof cache.get).toBe("function");
|
|
18
|
+
require_vi_bdSIJ99Y.globalExpect(typeof cache.set).toBe("function");
|
|
19
|
+
require_vi_bdSIJ99Y.globalExpect(typeof cache.delete).toBe("function");
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
require_vi_bdSIJ99Y.describe("method signatures", () => {
|
|
23
|
+
require_vi_bdSIJ99Y.it("should have correct get method signature", () => {
|
|
24
24
|
const cache = new require_memory.InMemoryCache();
|
|
25
25
|
const getResult = cache.get("test");
|
|
26
|
-
|
|
26
|
+
require_vi_bdSIJ99Y.globalExpect(getResult).toBeInstanceOf(Promise);
|
|
27
27
|
});
|
|
28
|
-
|
|
28
|
+
require_vi_bdSIJ99Y.it("should have correct set method signature", () => {
|
|
29
29
|
const cache = new require_memory.InMemoryCache();
|
|
30
30
|
const setResult = cache.set("test", "value");
|
|
31
|
-
|
|
31
|
+
require_vi_bdSIJ99Y.globalExpect(setResult).toBeInstanceOf(Promise);
|
|
32
32
|
});
|
|
33
|
-
|
|
33
|
+
require_vi_bdSIJ99Y.it("should have correct delete method signature", () => {
|
|
34
34
|
const cache = new require_memory.InMemoryCache();
|
|
35
35
|
const deleteResult = cache.delete("test");
|
|
36
|
-
|
|
36
|
+
require_vi_bdSIJ99Y.globalExpect(deleteResult).toBeInstanceOf(Promise);
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
require_vi_bdSIJ99Y.describe("generic type support", () => {
|
|
40
|
+
require_vi_bdSIJ99Y.it("should support string types", async () => {
|
|
41
41
|
const cache = new require_memory.InMemoryCache();
|
|
42
42
|
await cache.set("key", "value");
|
|
43
43
|
const result = await cache.get("key");
|
|
44
|
-
|
|
44
|
+
require_vi_bdSIJ99Y.globalExpect(typeof result === "string" || result === void 0).toBe(true);
|
|
45
45
|
});
|
|
46
|
-
|
|
46
|
+
require_vi_bdSIJ99Y.it("should support number types", async () => {
|
|
47
47
|
const cache = new require_memory.InMemoryCache();
|
|
48
48
|
await cache.set("key", 42);
|
|
49
49
|
const result = await cache.get("key");
|
|
50
|
-
|
|
50
|
+
require_vi_bdSIJ99Y.globalExpect(typeof result === "number" || result === void 0).toBe(true);
|
|
51
51
|
});
|
|
52
|
-
|
|
52
|
+
require_vi_bdSIJ99Y.it("should support object types", async () => {
|
|
53
53
|
const cache = new require_memory.InMemoryCache();
|
|
54
54
|
const user = {
|
|
55
55
|
id: 1,
|
|
@@ -57,9 +57,9 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
57
57
|
};
|
|
58
58
|
await cache.set("user", user);
|
|
59
59
|
const result = await cache.get("user");
|
|
60
|
-
|
|
60
|
+
require_vi_bdSIJ99Y.globalExpect(result === void 0 || typeof result === "object" && "id" in result && "name" in result).toBe(true);
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
require_vi_bdSIJ99Y.it("should support union types", async () => {
|
|
63
63
|
const cache = new require_memory.InMemoryCache();
|
|
64
64
|
await cache.set("string", "text");
|
|
65
65
|
await cache.set("number", 42);
|
|
@@ -67,9 +67,9 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
67
67
|
const stringResult = await cache.get("string");
|
|
68
68
|
const numberResult = await cache.get("number");
|
|
69
69
|
const booleanResult = await cache.get("boolean");
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
require_vi_bdSIJ99Y.globalExpect(stringResult).toBe("text");
|
|
71
|
+
require_vi_bdSIJ99Y.globalExpect(numberResult).toBe(42);
|
|
72
|
+
require_vi_bdSIJ99Y.globalExpect(booleanResult).toBe(true);
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
});
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { describe, globalExpect, it } from "../vi.bdSIJ99Y-CB5havZF.mjs";
|
|
2
|
+
import "../src-DVpoP03o.mjs";
|
|
3
|
+
import { InMemoryCache } from "../memory-QDTnSEX5.mjs";
|
|
4
|
+
import { UpstashCache } from "../upstash-CXy_duOa.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/__tests__/cache.spec.ts
|
|
6
7
|
describe("Cache Interface", () => {
|
|
7
8
|
describe("interface compliance", () => {
|
|
8
9
|
it("InMemoryCache should implement Cache interface", () => {
|
|
9
10
|
const cache = new InMemoryCache();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
globalExpect(typeof cache.get).toBe("function");
|
|
12
|
+
globalExpect(typeof cache.set).toBe("function");
|
|
13
|
+
globalExpect(typeof cache.delete).toBe("function");
|
|
13
14
|
});
|
|
14
15
|
it("UpstashCache should implement Cache interface", () => {
|
|
15
16
|
const cache = new UpstashCache("http://localhost:8079", "example_token");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
globalExpect(typeof cache.get).toBe("function");
|
|
18
|
+
globalExpect(typeof cache.set).toBe("function");
|
|
19
|
+
globalExpect(typeof cache.delete).toBe("function");
|
|
19
20
|
});
|
|
20
21
|
});
|
|
21
22
|
describe("method signatures", () => {
|
|
22
23
|
it("should have correct get method signature", () => {
|
|
23
24
|
const cache = new InMemoryCache();
|
|
24
25
|
const getResult = cache.get("test");
|
|
25
|
-
|
|
26
|
+
globalExpect(getResult).toBeInstanceOf(Promise);
|
|
26
27
|
});
|
|
27
28
|
it("should have correct set method signature", () => {
|
|
28
29
|
const cache = new InMemoryCache();
|
|
29
30
|
const setResult = cache.set("test", "value");
|
|
30
|
-
|
|
31
|
+
globalExpect(setResult).toBeInstanceOf(Promise);
|
|
31
32
|
});
|
|
32
33
|
it("should have correct delete method signature", () => {
|
|
33
34
|
const cache = new InMemoryCache();
|
|
34
35
|
const deleteResult = cache.delete("test");
|
|
35
|
-
|
|
36
|
+
globalExpect(deleteResult).toBeInstanceOf(Promise);
|
|
36
37
|
});
|
|
37
38
|
});
|
|
38
39
|
describe("generic type support", () => {
|
|
@@ -40,13 +41,13 @@ describe("Cache Interface", () => {
|
|
|
40
41
|
const cache = new InMemoryCache();
|
|
41
42
|
await cache.set("key", "value");
|
|
42
43
|
const result = await cache.get("key");
|
|
43
|
-
|
|
44
|
+
globalExpect(typeof result === "string" || result === void 0).toBe(true);
|
|
44
45
|
});
|
|
45
46
|
it("should support number types", async () => {
|
|
46
47
|
const cache = new InMemoryCache();
|
|
47
48
|
await cache.set("key", 42);
|
|
48
49
|
const result = await cache.get("key");
|
|
49
|
-
|
|
50
|
+
globalExpect(typeof result === "number" || result === void 0).toBe(true);
|
|
50
51
|
});
|
|
51
52
|
it("should support object types", async () => {
|
|
52
53
|
const cache = new InMemoryCache();
|
|
@@ -56,7 +57,7 @@ describe("Cache Interface", () => {
|
|
|
56
57
|
};
|
|
57
58
|
await cache.set("user", user);
|
|
58
59
|
const result = await cache.get("user");
|
|
59
|
-
|
|
60
|
+
globalExpect(result === void 0 || typeof result === "object" && "id" in result && "name" in result).toBe(true);
|
|
60
61
|
});
|
|
61
62
|
it("should support union types", async () => {
|
|
62
63
|
const cache = new InMemoryCache();
|
|
@@ -66,9 +67,9 @@ describe("Cache Interface", () => {
|
|
|
66
67
|
const stringResult = await cache.get("string");
|
|
67
68
|
const numberResult = await cache.get("number");
|
|
68
69
|
const booleanResult = await cache.get("boolean");
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
globalExpect(stringResult).toBe("text");
|
|
71
|
+
globalExpect(numberResult).toBe(42);
|
|
72
|
+
globalExpect(booleanResult).toBe(true);
|
|
72
73
|
});
|
|
73
74
|
});
|
|
74
75
|
});
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
const require_memory = require('../memory-
|
|
3
|
-
const
|
|
1
|
+
require('../src-C7d6HaTp.cjs');
|
|
2
|
+
const require_memory = require('../memory-Csy6J-Ak.cjs');
|
|
3
|
+
const require_vi_bdSIJ99Y = require('../vi.bdSIJ99Y-B-qkABPq.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/__tests__/integration.spec.ts
|
|
6
|
-
|
|
6
|
+
require_vi_bdSIJ99Y.describe("Cache Integration Tests", () => {
|
|
7
7
|
let memoryCache;
|
|
8
|
-
|
|
8
|
+
require_vi_bdSIJ99Y.beforeEach(() => {
|
|
9
9
|
memoryCache = new require_memory.InMemoryCache();
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
require_vi_bdSIJ99Y.describe("cross-cache behavior consistency", () => {
|
|
12
12
|
const testCases = [{
|
|
13
13
|
name: "InMemoryCache",
|
|
14
14
|
cache: () => new require_memory.InMemoryCache()
|
|
15
15
|
}];
|
|
16
16
|
testCases.forEach(({ name, cache }) => {
|
|
17
|
-
|
|
17
|
+
require_vi_bdSIJ99Y.describe(name, () => {
|
|
18
18
|
let cacheInstance;
|
|
19
|
-
|
|
19
|
+
require_vi_bdSIJ99Y.beforeEach(() => {
|
|
20
20
|
cacheInstance = cache();
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
require_vi_bdSIJ99Y.it("should handle basic CRUD operations", async () => {
|
|
23
23
|
await cacheInstance.set("user:1", {
|
|
24
24
|
id: 1,
|
|
25
25
|
name: "John"
|
|
26
26
|
});
|
|
27
27
|
const user = await cacheInstance.get("user:1");
|
|
28
|
-
|
|
28
|
+
require_vi_bdSIJ99Y.globalExpect(user).toEqual({
|
|
29
29
|
id: 1,
|
|
30
30
|
name: "John"
|
|
31
31
|
});
|
|
@@ -34,15 +34,15 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
34
34
|
name: "Jane"
|
|
35
35
|
});
|
|
36
36
|
const updatedUser = await cacheInstance.get("user:1");
|
|
37
|
-
|
|
37
|
+
require_vi_bdSIJ99Y.globalExpect(updatedUser).toEqual({
|
|
38
38
|
id: 1,
|
|
39
39
|
name: "Jane"
|
|
40
40
|
});
|
|
41
41
|
await cacheInstance.delete("user:1");
|
|
42
42
|
const deletedUser = await cacheInstance.get("user:1");
|
|
43
|
-
|
|
43
|
+
require_vi_bdSIJ99Y.globalExpect(deletedUser).toBeUndefined();
|
|
44
44
|
});
|
|
45
|
-
|
|
45
|
+
require_vi_bdSIJ99Y.it("should handle concurrent operations", async () => {
|
|
46
46
|
const operations = [
|
|
47
47
|
cacheInstance.set("key1", "value1"),
|
|
48
48
|
cacheInstance.set("key2", "value2"),
|
|
@@ -54,13 +54,13 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
54
54
|
cacheInstance.get("key2"),
|
|
55
55
|
cacheInstance.get("key3")
|
|
56
56
|
]);
|
|
57
|
-
|
|
57
|
+
require_vi_bdSIJ99Y.globalExpect(results).toEqual([
|
|
58
58
|
"value1",
|
|
59
59
|
"value2",
|
|
60
60
|
"value3"
|
|
61
61
|
]);
|
|
62
62
|
});
|
|
63
|
-
|
|
63
|
+
require_vi_bdSIJ99Y.it("should handle data type preservation", async () => {
|
|
64
64
|
const testData = {
|
|
65
65
|
string: "hello",
|
|
66
66
|
number: 42,
|
|
@@ -75,31 +75,31 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
75
75
|
};
|
|
76
76
|
await Promise.all(Object.entries(testData).map(([key, value]) => cacheInstance.set(key, value)));
|
|
77
77
|
const results = await Promise.all(Object.keys(testData).map((key) => cacheInstance.get(key)));
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
require_vi_bdSIJ99Y.globalExpect(results[0]).toBe("hello");
|
|
79
|
+
require_vi_bdSIJ99Y.globalExpect(results[1]).toBe(42);
|
|
80
|
+
require_vi_bdSIJ99Y.globalExpect(results[2]).toBe(true);
|
|
81
|
+
require_vi_bdSIJ99Y.globalExpect(results[3]).toEqual({ nested: true });
|
|
82
|
+
require_vi_bdSIJ99Y.globalExpect(results[4]).toEqual([
|
|
83
83
|
1,
|
|
84
84
|
2,
|
|
85
85
|
3
|
|
86
86
|
]);
|
|
87
|
-
|
|
87
|
+
require_vi_bdSIJ99Y.globalExpect(results[5]).toBeNull();
|
|
88
88
|
});
|
|
89
|
-
|
|
89
|
+
require_vi_bdSIJ99Y.it("should handle key isolation", async () => {
|
|
90
90
|
await cacheInstance.set("user:1", "User One");
|
|
91
91
|
await cacheInstance.set("user:2", "User Two");
|
|
92
92
|
await cacheInstance.set("session:1", "Session One");
|
|
93
93
|
await cacheInstance.delete("user:1");
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
require_vi_bdSIJ99Y.globalExpect(await cacheInstance.get("user:1")).toBeUndefined();
|
|
95
|
+
require_vi_bdSIJ99Y.globalExpect(await cacheInstance.get("user:2")).toBe("User Two");
|
|
96
|
+
require_vi_bdSIJ99Y.globalExpect(await cacheInstance.get("session:1")).toBe("Session One");
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
require_vi_bdSIJ99Y.describe("cache migration scenarios", () => {
|
|
102
|
+
require_vi_bdSIJ99Y.it("should support migrating data between cache implementations", async () => {
|
|
103
103
|
const sourceCache = new require_memory.InMemoryCache();
|
|
104
104
|
const targetCache = new require_memory.InMemoryCache();
|
|
105
105
|
const testData = {
|
|
@@ -124,12 +124,12 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
124
124
|
}
|
|
125
125
|
for (const [key, expectedValue] of Object.entries(testData)) {
|
|
126
126
|
const migratedValue = await targetCache.get(key);
|
|
127
|
-
|
|
127
|
+
require_vi_bdSIJ99Y.globalExpect(migratedValue).toEqual(expectedValue);
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
require_vi_bdSIJ99Y.describe("cache abstraction patterns", () => {
|
|
132
|
+
require_vi_bdSIJ99Y.it("should support cache factory pattern", async () => {
|
|
133
133
|
const createCache = (type) => {
|
|
134
134
|
switch (type) {
|
|
135
135
|
case "memory": return new require_memory.InMemoryCache();
|
|
@@ -143,13 +143,13 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
143
143
|
name: "John"
|
|
144
144
|
});
|
|
145
145
|
await sessionCache.set("session:abc", "active");
|
|
146
|
-
|
|
146
|
+
require_vi_bdSIJ99Y.globalExpect(await userCache.get("user:1")).toEqual({
|
|
147
147
|
id: 1,
|
|
148
148
|
name: "John"
|
|
149
149
|
});
|
|
150
|
-
|
|
150
|
+
require_vi_bdSIJ99Y.globalExpect(await sessionCache.get("session:abc")).toBe("active");
|
|
151
151
|
});
|
|
152
|
-
|
|
152
|
+
require_vi_bdSIJ99Y.it("should support cache wrapper pattern", async () => {
|
|
153
153
|
class LoggingCache {
|
|
154
154
|
logs = [];
|
|
155
155
|
constructor(underlying) {
|
|
@@ -177,28 +177,28 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
177
177
|
await loggingCache.get("test");
|
|
178
178
|
await loggingCache.delete("test");
|
|
179
179
|
const logs = loggingCache.getLogs();
|
|
180
|
-
|
|
180
|
+
require_vi_bdSIJ99Y.globalExpect(logs).toEqual([
|
|
181
181
|
"SET test",
|
|
182
182
|
"GET test",
|
|
183
183
|
"DELETE test"
|
|
184
184
|
]);
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
require_vi_bdSIJ99Y.describe("performance and stress tests", () => {
|
|
188
|
+
require_vi_bdSIJ99Y.it("should handle large number of operations", async () => {
|
|
189
189
|
const cache = new require_memory.InMemoryCache();
|
|
190
190
|
const operationCount = 1e3;
|
|
191
191
|
const insertPromises = Array.from({ length: operationCount }, (_, i) => cache.set(`key:${i}`, i));
|
|
192
192
|
await Promise.all(insertPromises);
|
|
193
193
|
const readPromises = Array.from({ length: operationCount }, (_, i) => cache.get(`key:${i}`));
|
|
194
194
|
const results = await Promise.all(readPromises);
|
|
195
|
-
for (let i = 0; i < operationCount; i++)
|
|
195
|
+
for (let i = 0; i < operationCount; i++) require_vi_bdSIJ99Y.globalExpect(results[i]).toBe(i);
|
|
196
196
|
const deletePromises = Array.from({ length: operationCount }, (_, i) => cache.delete(`key:${i}`));
|
|
197
197
|
await Promise.all(deletePromises);
|
|
198
198
|
const postDeleteRead = await cache.get("key:0");
|
|
199
|
-
|
|
199
|
+
require_vi_bdSIJ99Y.globalExpect(postDeleteRead).toBeUndefined();
|
|
200
200
|
});
|
|
201
|
-
|
|
201
|
+
require_vi_bdSIJ99Y.it("should handle large objects efficiently", async () => {
|
|
202
202
|
const cache = new require_memory.InMemoryCache();
|
|
203
203
|
const largeObject = {
|
|
204
204
|
id: 1,
|
|
@@ -215,19 +215,19 @@ const vitest = require_chunk.__toESM(require("vitest"));
|
|
|
215
215
|
await cache.set("large-object", largeObject);
|
|
216
216
|
const result = await cache.get("large-object");
|
|
217
217
|
const endTime = Date.now();
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
require_vi_bdSIJ99Y.globalExpect(result).toEqual(largeObject);
|
|
219
|
+
require_vi_bdSIJ99Y.globalExpect(endTime - startTime).toBeLessThan(100);
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
require_vi_bdSIJ99Y.describe("error scenarios", () => {
|
|
223
|
+
require_vi_bdSIJ99Y.it("should handle operations after errors gracefully", async () => {
|
|
224
224
|
const cache = new require_memory.InMemoryCache();
|
|
225
225
|
await cache.set("valid-key", "valid-value");
|
|
226
|
-
|
|
226
|
+
require_vi_bdSIJ99Y.globalExpect(await cache.get("valid-key")).toBe("valid-value");
|
|
227
227
|
await cache.set("another-key", "another-value");
|
|
228
|
-
|
|
228
|
+
require_vi_bdSIJ99Y.globalExpect(await cache.get("another-key")).toBe("another-value");
|
|
229
229
|
await cache.delete("valid-key");
|
|
230
|
-
|
|
230
|
+
require_vi_bdSIJ99Y.globalExpect(await cache.get("valid-key")).toBeUndefined();
|
|
231
231
|
});
|
|
232
232
|
});
|
|
233
233
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { beforeEach, describe, globalExpect, it } from "../vi.bdSIJ99Y-CB5havZF.mjs";
|
|
2
|
+
import "../src-DVpoP03o.mjs";
|
|
3
|
+
import { InMemoryCache } from "../memory-QDTnSEX5.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/__tests__/integration.spec.ts
|
|
5
6
|
describe("Cache Integration Tests", () => {
|
|
@@ -24,7 +25,7 @@ describe("Cache Integration Tests", () => {
|
|
|
24
25
|
name: "John"
|
|
25
26
|
});
|
|
26
27
|
const user = await cacheInstance.get("user:1");
|
|
27
|
-
|
|
28
|
+
globalExpect(user).toEqual({
|
|
28
29
|
id: 1,
|
|
29
30
|
name: "John"
|
|
30
31
|
});
|
|
@@ -33,13 +34,13 @@ describe("Cache Integration Tests", () => {
|
|
|
33
34
|
name: "Jane"
|
|
34
35
|
});
|
|
35
36
|
const updatedUser = await cacheInstance.get("user:1");
|
|
36
|
-
|
|
37
|
+
globalExpect(updatedUser).toEqual({
|
|
37
38
|
id: 1,
|
|
38
39
|
name: "Jane"
|
|
39
40
|
});
|
|
40
41
|
await cacheInstance.delete("user:1");
|
|
41
42
|
const deletedUser = await cacheInstance.get("user:1");
|
|
42
|
-
|
|
43
|
+
globalExpect(deletedUser).toBeUndefined();
|
|
43
44
|
});
|
|
44
45
|
it("should handle concurrent operations", async () => {
|
|
45
46
|
const operations = [
|
|
@@ -53,7 +54,7 @@ describe("Cache Integration Tests", () => {
|
|
|
53
54
|
cacheInstance.get("key2"),
|
|
54
55
|
cacheInstance.get("key3")
|
|
55
56
|
]);
|
|
56
|
-
|
|
57
|
+
globalExpect(results).toEqual([
|
|
57
58
|
"value1",
|
|
58
59
|
"value2",
|
|
59
60
|
"value3"
|
|
@@ -74,25 +75,25 @@ describe("Cache Integration Tests", () => {
|
|
|
74
75
|
};
|
|
75
76
|
await Promise.all(Object.entries(testData).map(([key, value]) => cacheInstance.set(key, value)));
|
|
76
77
|
const results = await Promise.all(Object.keys(testData).map((key) => cacheInstance.get(key)));
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
globalExpect(results[0]).toBe("hello");
|
|
79
|
+
globalExpect(results[1]).toBe(42);
|
|
80
|
+
globalExpect(results[2]).toBe(true);
|
|
81
|
+
globalExpect(results[3]).toEqual({ nested: true });
|
|
82
|
+
globalExpect(results[4]).toEqual([
|
|
82
83
|
1,
|
|
83
84
|
2,
|
|
84
85
|
3
|
|
85
86
|
]);
|
|
86
|
-
|
|
87
|
+
globalExpect(results[5]).toBeNull();
|
|
87
88
|
});
|
|
88
89
|
it("should handle key isolation", async () => {
|
|
89
90
|
await cacheInstance.set("user:1", "User One");
|
|
90
91
|
await cacheInstance.set("user:2", "User Two");
|
|
91
92
|
await cacheInstance.set("session:1", "Session One");
|
|
92
93
|
await cacheInstance.delete("user:1");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
globalExpect(await cacheInstance.get("user:1")).toBeUndefined();
|
|
95
|
+
globalExpect(await cacheInstance.get("user:2")).toBe("User Two");
|
|
96
|
+
globalExpect(await cacheInstance.get("session:1")).toBe("Session One");
|
|
96
97
|
});
|
|
97
98
|
});
|
|
98
99
|
});
|
|
@@ -123,7 +124,7 @@ describe("Cache Integration Tests", () => {
|
|
|
123
124
|
}
|
|
124
125
|
for (const [key, expectedValue] of Object.entries(testData)) {
|
|
125
126
|
const migratedValue = await targetCache.get(key);
|
|
126
|
-
|
|
127
|
+
globalExpect(migratedValue).toEqual(expectedValue);
|
|
127
128
|
}
|
|
128
129
|
});
|
|
129
130
|
});
|
|
@@ -142,11 +143,11 @@ describe("Cache Integration Tests", () => {
|
|
|
142
143
|
name: "John"
|
|
143
144
|
});
|
|
144
145
|
await sessionCache.set("session:abc", "active");
|
|
145
|
-
|
|
146
|
+
globalExpect(await userCache.get("user:1")).toEqual({
|
|
146
147
|
id: 1,
|
|
147
148
|
name: "John"
|
|
148
149
|
});
|
|
149
|
-
|
|
150
|
+
globalExpect(await sessionCache.get("session:abc")).toBe("active");
|
|
150
151
|
});
|
|
151
152
|
it("should support cache wrapper pattern", async () => {
|
|
152
153
|
class LoggingCache {
|
|
@@ -176,7 +177,7 @@ describe("Cache Integration Tests", () => {
|
|
|
176
177
|
await loggingCache.get("test");
|
|
177
178
|
await loggingCache.delete("test");
|
|
178
179
|
const logs = loggingCache.getLogs();
|
|
179
|
-
|
|
180
|
+
globalExpect(logs).toEqual([
|
|
180
181
|
"SET test",
|
|
181
182
|
"GET test",
|
|
182
183
|
"DELETE test"
|
|
@@ -191,11 +192,11 @@ describe("Cache Integration Tests", () => {
|
|
|
191
192
|
await Promise.all(insertPromises);
|
|
192
193
|
const readPromises = Array.from({ length: operationCount }, (_, i) => cache.get(`key:${i}`));
|
|
193
194
|
const results = await Promise.all(readPromises);
|
|
194
|
-
for (let i = 0; i < operationCount; i++)
|
|
195
|
+
for (let i = 0; i < operationCount; i++) globalExpect(results[i]).toBe(i);
|
|
195
196
|
const deletePromises = Array.from({ length: operationCount }, (_, i) => cache.delete(`key:${i}`));
|
|
196
197
|
await Promise.all(deletePromises);
|
|
197
198
|
const postDeleteRead = await cache.get("key:0");
|
|
198
|
-
|
|
199
|
+
globalExpect(postDeleteRead).toBeUndefined();
|
|
199
200
|
});
|
|
200
201
|
it("should handle large objects efficiently", async () => {
|
|
201
202
|
const cache = new InMemoryCache();
|
|
@@ -214,19 +215,19 @@ describe("Cache Integration Tests", () => {
|
|
|
214
215
|
await cache.set("large-object", largeObject);
|
|
215
216
|
const result = await cache.get("large-object");
|
|
216
217
|
const endTime = Date.now();
|
|
217
|
-
|
|
218
|
-
|
|
218
|
+
globalExpect(result).toEqual(largeObject);
|
|
219
|
+
globalExpect(endTime - startTime).toBeLessThan(100);
|
|
219
220
|
});
|
|
220
221
|
});
|
|
221
222
|
describe("error scenarios", () => {
|
|
222
223
|
it("should handle operations after errors gracefully", async () => {
|
|
223
224
|
const cache = new InMemoryCache();
|
|
224
225
|
await cache.set("valid-key", "valid-value");
|
|
225
|
-
|
|
226
|
+
globalExpect(await cache.get("valid-key")).toBe("valid-value");
|
|
226
227
|
await cache.set("another-key", "another-value");
|
|
227
|
-
|
|
228
|
+
globalExpect(await cache.get("another-key")).toBe("another-value");
|
|
228
229
|
await cache.delete("valid-key");
|
|
229
|
-
|
|
230
|
+
globalExpect(await cache.get("valid-key")).toBeUndefined();
|
|
230
231
|
});
|
|
231
232
|
});
|
|
232
233
|
});
|