@geekmidas/cache 0.0.7 → 0.1.0
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/{chunk-DWy1uDak.cjs → chunk-CUT6urMc.cjs} +0 -9
- package/dist/expo.cjs +4 -3
- package/dist/expo.cjs.map +1 -0
- package/dist/expo.d.cts +6 -5
- package/dist/expo.d.mts +6 -5
- package/dist/expo.mjs +3 -2
- package/dist/expo.mjs.map +1 -0
- package/dist/{index-B6eF5Yxi.d.cts → index-CExVL1mV.d.cts} +7 -5
- package/dist/{index-Bv61mxVT.d.mts → index-M02PehQA.d.mts} +7 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/memory.cjs +35 -3
- package/dist/memory.cjs.map +1 -0
- package/dist/memory.d.cts +6 -5
- package/dist/memory.d.mts +6 -5
- package/dist/memory.mjs +34 -3
- package/dist/memory.mjs.map +1 -0
- package/dist/{src-DVpoP03o.mjs → src-CrE4Nl5T.mjs} +2 -1
- package/dist/src-CrE4Nl5T.mjs.map +1 -0
- package/dist/{src-C7d6HaTp.cjs → src-zfYb7mdS.cjs} +3 -2
- package/dist/src-zfYb7mdS.cjs.map +1 -0
- package/dist/upstash.cjs +32 -2
- package/dist/upstash.cjs.map +1 -0
- package/dist/upstash.d.cts +6 -5
- package/dist/upstash.d.mts +6 -5
- package/dist/upstash.mjs +31 -2
- package/dist/upstash.mjs.map +1 -0
- package/package.json +6 -2
- package/src/__benchmarks__/memory.bench.ts +51 -0
- package/src/__tests__/cache.spec.ts +31 -35
- package/src/__tests__/integration.spec.ts +32 -23
- package/src/__tests__/memory.spec.ts +1 -1
- package/src/__tests__/upstash.spec.ts +1 -1
- package/src/expo.ts +3 -4
- package/src/index.ts +5 -4
- package/src/memory.ts +6 -5
- package/src/upstash.ts +4 -4
- package/dist/__tests__/cache.spec.cjs +0 -77
- package/dist/__tests__/cache.spec.d.cts +0 -1
- package/dist/__tests__/cache.spec.d.mts +0 -1
- package/dist/__tests__/cache.spec.mjs +0 -77
- package/dist/__tests__/integration.spec.cjs +0 -235
- package/dist/__tests__/integration.spec.d.cts +0 -1
- package/dist/__tests__/integration.spec.d.mts +0 -1
- package/dist/__tests__/integration.spec.mjs +0 -235
- package/dist/__tests__/memory.spec.cjs +0 -126
- package/dist/__tests__/memory.spec.d.cts +0 -1
- package/dist/__tests__/memory.spec.d.mts +0 -1
- package/dist/__tests__/memory.spec.mjs +0 -126
- package/dist/__tests__/upstash.spec.cjs +0 -201
- package/dist/__tests__/upstash.spec.d.cts +0 -1
- package/dist/__tests__/upstash.spec.d.mts +0 -1
- package/dist/__tests__/upstash.spec.mjs +0 -201
- package/dist/magic-string.es-CBih0MJw.mjs +0 -1014
- package/dist/magic-string.es-KiPEzMtt.cjs +0 -1015
- package/dist/memory-Csy6J-Ak.cjs +0 -39
- package/dist/memory-QDTnSEX5.mjs +0 -33
- package/dist/upstash-CXy_duOa.mjs +0 -31
- package/dist/upstash-u8Hs4sZG.cjs +0 -37
- package/dist/vi.bdSIJ99Y-B-qkABPq.cjs +0 -14955
- package/dist/vi.bdSIJ99Y-CB5havZF.mjs +0 -14951
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, globalExpect, it } from "../vi.bdSIJ99Y-CB5havZF.mjs";
|
|
2
|
-
import "../src-DVpoP03o.mjs";
|
|
3
|
-
import { InMemoryCache } from "../memory-QDTnSEX5.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/__tests__/memory.spec.ts
|
|
6
|
-
describe("InMemoryCache", () => {
|
|
7
|
-
let cache;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
cache = new InMemoryCache();
|
|
10
|
-
});
|
|
11
|
-
describe("get", () => {
|
|
12
|
-
it("should return undefined for non-existent key", async () => {
|
|
13
|
-
const result = await cache.get("non-existent");
|
|
14
|
-
globalExpect(result).toBeUndefined();
|
|
15
|
-
});
|
|
16
|
-
it("should return value for existing key", async () => {
|
|
17
|
-
await cache.set("test-key", "test-value");
|
|
18
|
-
const result = await cache.get("test-key");
|
|
19
|
-
globalExpect(result).toBe("test-value");
|
|
20
|
-
});
|
|
21
|
-
it("should handle different data types", async () => {
|
|
22
|
-
const objectValue = {
|
|
23
|
-
id: 1,
|
|
24
|
-
name: "test"
|
|
25
|
-
};
|
|
26
|
-
const arrayValue = [
|
|
27
|
-
1,
|
|
28
|
-
2,
|
|
29
|
-
3
|
|
30
|
-
];
|
|
31
|
-
const numberValue = 42;
|
|
32
|
-
const booleanValue = true;
|
|
33
|
-
await cache.set("object", objectValue);
|
|
34
|
-
await cache.set("array", arrayValue);
|
|
35
|
-
await cache.set("number", numberValue);
|
|
36
|
-
await cache.set("boolean", booleanValue);
|
|
37
|
-
globalExpect(await cache.get("object")).toEqual(objectValue);
|
|
38
|
-
globalExpect(await cache.get("array")).toEqual(arrayValue);
|
|
39
|
-
globalExpect(await cache.get("number")).toBe(numberValue);
|
|
40
|
-
globalExpect(await cache.get("boolean")).toBe(booleanValue);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe("set", () => {
|
|
44
|
-
it("should store string value", async () => {
|
|
45
|
-
await cache.set("string-key", "string-value");
|
|
46
|
-
const result = await cache.get("string-key");
|
|
47
|
-
globalExpect(result).toBe("string-value");
|
|
48
|
-
});
|
|
49
|
-
it("should store object value", async () => {
|
|
50
|
-
const value = {
|
|
51
|
-
id: 1,
|
|
52
|
-
data: "test"
|
|
53
|
-
};
|
|
54
|
-
await cache.set("object-key", value);
|
|
55
|
-
const result = await cache.get("object-key");
|
|
56
|
-
globalExpect(result).toEqual(value);
|
|
57
|
-
});
|
|
58
|
-
it("should overwrite existing value", async () => {
|
|
59
|
-
await cache.set("key", "initial-value");
|
|
60
|
-
await cache.set("key", "updated-value");
|
|
61
|
-
const result = await cache.get("key");
|
|
62
|
-
globalExpect(result).toBe("updated-value");
|
|
63
|
-
});
|
|
64
|
-
it("should handle null values", async () => {
|
|
65
|
-
await cache.set("null-key", null);
|
|
66
|
-
const result = await cache.get("null-key");
|
|
67
|
-
globalExpect(result).toBeNull();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
describe("delete", () => {
|
|
71
|
-
it("should remove existing key", async () => {
|
|
72
|
-
await cache.set("to-delete", "value");
|
|
73
|
-
await cache.delete("to-delete");
|
|
74
|
-
const result = await cache.get("to-delete");
|
|
75
|
-
globalExpect(result).toBeUndefined();
|
|
76
|
-
});
|
|
77
|
-
it("should not throw error for non-existent key", async () => {
|
|
78
|
-
await globalExpect(cache.delete("non-existent")).resolves.not.toThrow();
|
|
79
|
-
});
|
|
80
|
-
it("should only delete specified key", async () => {
|
|
81
|
-
await cache.set("key1", "value1");
|
|
82
|
-
await cache.set("key2", "value2");
|
|
83
|
-
await cache.delete("key1");
|
|
84
|
-
globalExpect(await cache.get("key1")).toBeUndefined();
|
|
85
|
-
globalExpect(await cache.get("key2")).toBe("value2");
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe("multiple operations", () => {
|
|
89
|
-
it("should handle multiple keys independently", async () => {
|
|
90
|
-
await cache.set("key1", "value1");
|
|
91
|
-
await cache.set("key2", "value2");
|
|
92
|
-
await cache.set("key3", "value3");
|
|
93
|
-
globalExpect(await cache.get("key1")).toBe("value1");
|
|
94
|
-
globalExpect(await cache.get("key2")).toBe("value2");
|
|
95
|
-
globalExpect(await cache.get("key3")).toBe("value3");
|
|
96
|
-
});
|
|
97
|
-
it("should maintain data integrity across operations", async () => {
|
|
98
|
-
const data = { count: 0 };
|
|
99
|
-
await cache.set("counter", data);
|
|
100
|
-
const retrieved = await cache.get("counter");
|
|
101
|
-
retrieved.count = 5;
|
|
102
|
-
const original = await cache.get("counter");
|
|
103
|
-
globalExpect(original.count).toBe(5);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe("edge cases", () => {
|
|
107
|
-
it("should handle empty string as key", async () => {
|
|
108
|
-
await cache.set("", "empty-key-value");
|
|
109
|
-
const result = await cache.get("");
|
|
110
|
-
globalExpect(result).toBe("empty-key-value");
|
|
111
|
-
});
|
|
112
|
-
it("should handle special characters in keys", async () => {
|
|
113
|
-
const specialKey = "key!@#$%^&*()_+{}|:\"<>?[]\\;',./?`~";
|
|
114
|
-
await cache.set(specialKey, "special-value");
|
|
115
|
-
const result = await cache.get(specialKey);
|
|
116
|
-
globalExpect(result).toBe("special-value");
|
|
117
|
-
});
|
|
118
|
-
it("should handle undefined values", async () => {
|
|
119
|
-
await cache.set("undefined-key", void 0);
|
|
120
|
-
const result = await cache.get("undefined-key");
|
|
121
|
-
globalExpect(result).toBeUndefined();
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
const require_upstash = require('../upstash-u8Hs4sZG.cjs');
|
|
2
|
-
const require_vi_bdSIJ99Y = require('../vi.bdSIJ99Y-B-qkABPq.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/__tests__/upstash.spec.ts
|
|
5
|
-
require_vi_bdSIJ99Y.describe("UpstashCache", () => {
|
|
6
|
-
let cache;
|
|
7
|
-
const testKeyPrefix = `test:${Date.now()}:`;
|
|
8
|
-
let testKeys = [];
|
|
9
|
-
require_vi_bdSIJ99Y.beforeEach(() => {
|
|
10
|
-
cache = new require_upstash.UpstashCache("http://localhost:8079", "example_token");
|
|
11
|
-
testKeys = [];
|
|
12
|
-
});
|
|
13
|
-
require_vi_bdSIJ99Y.afterEach(async () => {
|
|
14
|
-
for (const key of testKeys) try {
|
|
15
|
-
await cache.delete(key);
|
|
16
|
-
} catch (error) {}
|
|
17
|
-
});
|
|
18
|
-
const getTestKey = (suffix) => {
|
|
19
|
-
const key = `${testKeyPrefix}${suffix}`;
|
|
20
|
-
testKeys.push(key);
|
|
21
|
-
return key;
|
|
22
|
-
};
|
|
23
|
-
require_vi_bdSIJ99Y.describe("get", () => {
|
|
24
|
-
require_vi_bdSIJ99Y.it("should return undefined for non-existent key", async () => {
|
|
25
|
-
const key = getTestKey("non-existent");
|
|
26
|
-
const result = await cache.get(key);
|
|
27
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBeUndefined();
|
|
28
|
-
});
|
|
29
|
-
require_vi_bdSIJ99Y.it("should parse and return JSON value", async () => {
|
|
30
|
-
const key = getTestKey("object");
|
|
31
|
-
const testValue = {
|
|
32
|
-
id: 1,
|
|
33
|
-
name: "test"
|
|
34
|
-
};
|
|
35
|
-
await cache.set(key, testValue);
|
|
36
|
-
const result = await cache.get(key);
|
|
37
|
-
require_vi_bdSIJ99Y.globalExpect(result).toEqual(testValue);
|
|
38
|
-
});
|
|
39
|
-
require_vi_bdSIJ99Y.it("should handle string values", async () => {
|
|
40
|
-
const key = getTestKey("string");
|
|
41
|
-
const testValue = "simple string";
|
|
42
|
-
await cache.set(key, testValue);
|
|
43
|
-
const result = await cache.get(key);
|
|
44
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBe(testValue);
|
|
45
|
-
});
|
|
46
|
-
require_vi_bdSIJ99Y.it("should handle number values", async () => {
|
|
47
|
-
const key = getTestKey("number");
|
|
48
|
-
const testValue = 42;
|
|
49
|
-
await cache.set(key, testValue);
|
|
50
|
-
const result = await cache.get(key);
|
|
51
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBe(testValue);
|
|
52
|
-
});
|
|
53
|
-
require_vi_bdSIJ99Y.it("should handle boolean values", async () => {
|
|
54
|
-
const key = getTestKey("boolean");
|
|
55
|
-
const testValue = true;
|
|
56
|
-
await cache.set(key, testValue);
|
|
57
|
-
const result = await cache.get(key);
|
|
58
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBe(testValue);
|
|
59
|
-
});
|
|
60
|
-
require_vi_bdSIJ99Y.it("should handle array values", async () => {
|
|
61
|
-
const key = getTestKey("array");
|
|
62
|
-
const testArray = [
|
|
63
|
-
1,
|
|
64
|
-
2,
|
|
65
|
-
3,
|
|
66
|
-
"test"
|
|
67
|
-
];
|
|
68
|
-
await cache.set(key, testArray);
|
|
69
|
-
const result = await cache.get(key);
|
|
70
|
-
require_vi_bdSIJ99Y.globalExpect(result).toEqual(testArray);
|
|
71
|
-
});
|
|
72
|
-
require_vi_bdSIJ99Y.it("should handle null values as undefined", async () => {
|
|
73
|
-
const key = getTestKey("null");
|
|
74
|
-
await cache.set(key, null);
|
|
75
|
-
const result = await cache.get(key);
|
|
76
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBeUndefined();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
require_vi_bdSIJ99Y.describe("set", () => {
|
|
80
|
-
require_vi_bdSIJ99Y.it("should store and retrieve object value", async () => {
|
|
81
|
-
const key = getTestKey("set-object");
|
|
82
|
-
const testValue = {
|
|
83
|
-
id: 1,
|
|
84
|
-
name: "test"
|
|
85
|
-
};
|
|
86
|
-
await cache.set(key, testValue);
|
|
87
|
-
const result = await cache.get(key);
|
|
88
|
-
require_vi_bdSIJ99Y.globalExpect(result).toEqual(testValue);
|
|
89
|
-
});
|
|
90
|
-
require_vi_bdSIJ99Y.it("should store and retrieve string values", async () => {
|
|
91
|
-
const key = getTestKey("set-string");
|
|
92
|
-
const testValue = "test string";
|
|
93
|
-
await cache.set(key, testValue);
|
|
94
|
-
const result = await cache.get(key);
|
|
95
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBe(testValue);
|
|
96
|
-
});
|
|
97
|
-
require_vi_bdSIJ99Y.it("should store and retrieve number values", async () => {
|
|
98
|
-
const key = getTestKey("set-number");
|
|
99
|
-
const testValue = 42;
|
|
100
|
-
await cache.set(key, testValue);
|
|
101
|
-
const result = await cache.get(key);
|
|
102
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBe(testValue);
|
|
103
|
-
});
|
|
104
|
-
require_vi_bdSIJ99Y.it("should store and retrieve boolean values", async () => {
|
|
105
|
-
const key = getTestKey("set-boolean");
|
|
106
|
-
const testValue = true;
|
|
107
|
-
await cache.set(key, testValue);
|
|
108
|
-
const result = await cache.get(key);
|
|
109
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBe(testValue);
|
|
110
|
-
});
|
|
111
|
-
require_vi_bdSIJ99Y.it("should store and retrieve array values", async () => {
|
|
112
|
-
const key = getTestKey("set-array");
|
|
113
|
-
const testArray = [
|
|
114
|
-
1,
|
|
115
|
-
2,
|
|
116
|
-
3
|
|
117
|
-
];
|
|
118
|
-
await cache.set(key, testArray);
|
|
119
|
-
const result = await cache.get(key);
|
|
120
|
-
require_vi_bdSIJ99Y.globalExpect(result).toEqual(testArray);
|
|
121
|
-
});
|
|
122
|
-
require_vi_bdSIJ99Y.it("should not store and retrieve null values", async () => {
|
|
123
|
-
const key = getTestKey("set-null");
|
|
124
|
-
await cache.set(key, null);
|
|
125
|
-
const result = await cache.get(key);
|
|
126
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBeUndefined();
|
|
127
|
-
});
|
|
128
|
-
require_vi_bdSIJ99Y.it("should overwrite existing values", async () => {
|
|
129
|
-
const key = getTestKey("overwrite");
|
|
130
|
-
await cache.set(key, "initial");
|
|
131
|
-
await cache.set(key, "updated");
|
|
132
|
-
const result = await cache.get(key);
|
|
133
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBe("updated");
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
require_vi_bdSIJ99Y.describe("delete", () => {
|
|
137
|
-
require_vi_bdSIJ99Y.it("should delete existing key", async () => {
|
|
138
|
-
const key = getTestKey("delete-test");
|
|
139
|
-
await cache.set(key, "value-to-delete");
|
|
140
|
-
await cache.delete(key);
|
|
141
|
-
const result = await cache.get(key);
|
|
142
|
-
require_vi_bdSIJ99Y.globalExpect(result).toBeUndefined();
|
|
143
|
-
});
|
|
144
|
-
require_vi_bdSIJ99Y.it("should handle deletion of non-existent key", async () => {
|
|
145
|
-
const key = getTestKey("non-existent-delete");
|
|
146
|
-
await require_vi_bdSIJ99Y.globalExpect(cache.delete(key)).resolves.not.toThrow();
|
|
147
|
-
});
|
|
148
|
-
require_vi_bdSIJ99Y.it("should only delete specified key", async () => {
|
|
149
|
-
const key1 = getTestKey("delete-key1");
|
|
150
|
-
const key2 = getTestKey("delete-key2");
|
|
151
|
-
await cache.set(key1, "value1");
|
|
152
|
-
await cache.set(key2, "value2");
|
|
153
|
-
await cache.delete(key1);
|
|
154
|
-
require_vi_bdSIJ99Y.globalExpect(await cache.get(key1)).toBeUndefined();
|
|
155
|
-
require_vi_bdSIJ99Y.globalExpect(await cache.get(key2)).toBe("value2");
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
require_vi_bdSIJ99Y.describe("integration scenarios", () => {
|
|
159
|
-
require_vi_bdSIJ99Y.it("should handle round-trip operations", async () => {
|
|
160
|
-
const key = getTestKey("user-session");
|
|
161
|
-
const testData = {
|
|
162
|
-
user: {
|
|
163
|
-
id: 1,
|
|
164
|
-
name: "John"
|
|
165
|
-
},
|
|
166
|
-
preferences: ["dark-mode", "notifications"],
|
|
167
|
-
count: 42
|
|
168
|
-
};
|
|
169
|
-
await cache.set(key, testData);
|
|
170
|
-
const result = await cache.get(key);
|
|
171
|
-
require_vi_bdSIJ99Y.globalExpect(result).toEqual(testData);
|
|
172
|
-
});
|
|
173
|
-
require_vi_bdSIJ99Y.it("should handle complex nested objects", async () => {
|
|
174
|
-
const key = getTestKey("complex");
|
|
175
|
-
const complexObject = { level1: { level2: { level3: {
|
|
176
|
-
data: "deep nested value",
|
|
177
|
-
array: [{ id: 1 }, { id: 2 }]
|
|
178
|
-
} } } };
|
|
179
|
-
await cache.set(key, complexObject);
|
|
180
|
-
const result = await cache.get(key);
|
|
181
|
-
require_vi_bdSIJ99Y.globalExpect(result).toEqual(complexObject);
|
|
182
|
-
});
|
|
183
|
-
require_vi_bdSIJ99Y.it("should handle concurrent operations", async () => {
|
|
184
|
-
const keys = [
|
|
185
|
-
"concurrent1",
|
|
186
|
-
"concurrent2",
|
|
187
|
-
"concurrent3"
|
|
188
|
-
].map((suffix) => getTestKey(suffix));
|
|
189
|
-
const values = [
|
|
190
|
-
"value1",
|
|
191
|
-
"value2",
|
|
192
|
-
"value3"
|
|
193
|
-
];
|
|
194
|
-
await Promise.all(keys.map((key, i) => cache.set(key, values[i])));
|
|
195
|
-
const results = await Promise.all(keys.map((key) => cache.get(key)));
|
|
196
|
-
require_vi_bdSIJ99Y.globalExpect(results).toEqual(values);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.bdSIJ99Y-CB5havZF.mjs";
|
|
2
|
-
import { UpstashCache } from "../upstash-CXy_duOa.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/__tests__/upstash.spec.ts
|
|
5
|
-
describe("UpstashCache", () => {
|
|
6
|
-
let cache;
|
|
7
|
-
const testKeyPrefix = `test:${Date.now()}:`;
|
|
8
|
-
let testKeys = [];
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
cache = new UpstashCache("http://localhost:8079", "example_token");
|
|
11
|
-
testKeys = [];
|
|
12
|
-
});
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
for (const key of testKeys) try {
|
|
15
|
-
await cache.delete(key);
|
|
16
|
-
} catch (error) {}
|
|
17
|
-
});
|
|
18
|
-
const getTestKey = (suffix) => {
|
|
19
|
-
const key = `${testKeyPrefix}${suffix}`;
|
|
20
|
-
testKeys.push(key);
|
|
21
|
-
return key;
|
|
22
|
-
};
|
|
23
|
-
describe("get", () => {
|
|
24
|
-
it("should return undefined for non-existent key", async () => {
|
|
25
|
-
const key = getTestKey("non-existent");
|
|
26
|
-
const result = await cache.get(key);
|
|
27
|
-
globalExpect(result).toBeUndefined();
|
|
28
|
-
});
|
|
29
|
-
it("should parse and return JSON value", async () => {
|
|
30
|
-
const key = getTestKey("object");
|
|
31
|
-
const testValue = {
|
|
32
|
-
id: 1,
|
|
33
|
-
name: "test"
|
|
34
|
-
};
|
|
35
|
-
await cache.set(key, testValue);
|
|
36
|
-
const result = await cache.get(key);
|
|
37
|
-
globalExpect(result).toEqual(testValue);
|
|
38
|
-
});
|
|
39
|
-
it("should handle string values", async () => {
|
|
40
|
-
const key = getTestKey("string");
|
|
41
|
-
const testValue = "simple string";
|
|
42
|
-
await cache.set(key, testValue);
|
|
43
|
-
const result = await cache.get(key);
|
|
44
|
-
globalExpect(result).toBe(testValue);
|
|
45
|
-
});
|
|
46
|
-
it("should handle number values", async () => {
|
|
47
|
-
const key = getTestKey("number");
|
|
48
|
-
const testValue = 42;
|
|
49
|
-
await cache.set(key, testValue);
|
|
50
|
-
const result = await cache.get(key);
|
|
51
|
-
globalExpect(result).toBe(testValue);
|
|
52
|
-
});
|
|
53
|
-
it("should handle boolean values", async () => {
|
|
54
|
-
const key = getTestKey("boolean");
|
|
55
|
-
const testValue = true;
|
|
56
|
-
await cache.set(key, testValue);
|
|
57
|
-
const result = await cache.get(key);
|
|
58
|
-
globalExpect(result).toBe(testValue);
|
|
59
|
-
});
|
|
60
|
-
it("should handle array values", async () => {
|
|
61
|
-
const key = getTestKey("array");
|
|
62
|
-
const testArray = [
|
|
63
|
-
1,
|
|
64
|
-
2,
|
|
65
|
-
3,
|
|
66
|
-
"test"
|
|
67
|
-
];
|
|
68
|
-
await cache.set(key, testArray);
|
|
69
|
-
const result = await cache.get(key);
|
|
70
|
-
globalExpect(result).toEqual(testArray);
|
|
71
|
-
});
|
|
72
|
-
it("should handle null values as undefined", async () => {
|
|
73
|
-
const key = getTestKey("null");
|
|
74
|
-
await cache.set(key, null);
|
|
75
|
-
const result = await cache.get(key);
|
|
76
|
-
globalExpect(result).toBeUndefined();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
describe("set", () => {
|
|
80
|
-
it("should store and retrieve object value", async () => {
|
|
81
|
-
const key = getTestKey("set-object");
|
|
82
|
-
const testValue = {
|
|
83
|
-
id: 1,
|
|
84
|
-
name: "test"
|
|
85
|
-
};
|
|
86
|
-
await cache.set(key, testValue);
|
|
87
|
-
const result = await cache.get(key);
|
|
88
|
-
globalExpect(result).toEqual(testValue);
|
|
89
|
-
});
|
|
90
|
-
it("should store and retrieve string values", async () => {
|
|
91
|
-
const key = getTestKey("set-string");
|
|
92
|
-
const testValue = "test string";
|
|
93
|
-
await cache.set(key, testValue);
|
|
94
|
-
const result = await cache.get(key);
|
|
95
|
-
globalExpect(result).toBe(testValue);
|
|
96
|
-
});
|
|
97
|
-
it("should store and retrieve number values", async () => {
|
|
98
|
-
const key = getTestKey("set-number");
|
|
99
|
-
const testValue = 42;
|
|
100
|
-
await cache.set(key, testValue);
|
|
101
|
-
const result = await cache.get(key);
|
|
102
|
-
globalExpect(result).toBe(testValue);
|
|
103
|
-
});
|
|
104
|
-
it("should store and retrieve boolean values", async () => {
|
|
105
|
-
const key = getTestKey("set-boolean");
|
|
106
|
-
const testValue = true;
|
|
107
|
-
await cache.set(key, testValue);
|
|
108
|
-
const result = await cache.get(key);
|
|
109
|
-
globalExpect(result).toBe(testValue);
|
|
110
|
-
});
|
|
111
|
-
it("should store and retrieve array values", async () => {
|
|
112
|
-
const key = getTestKey("set-array");
|
|
113
|
-
const testArray = [
|
|
114
|
-
1,
|
|
115
|
-
2,
|
|
116
|
-
3
|
|
117
|
-
];
|
|
118
|
-
await cache.set(key, testArray);
|
|
119
|
-
const result = await cache.get(key);
|
|
120
|
-
globalExpect(result).toEqual(testArray);
|
|
121
|
-
});
|
|
122
|
-
it("should not store and retrieve null values", async () => {
|
|
123
|
-
const key = getTestKey("set-null");
|
|
124
|
-
await cache.set(key, null);
|
|
125
|
-
const result = await cache.get(key);
|
|
126
|
-
globalExpect(result).toBeUndefined();
|
|
127
|
-
});
|
|
128
|
-
it("should overwrite existing values", async () => {
|
|
129
|
-
const key = getTestKey("overwrite");
|
|
130
|
-
await cache.set(key, "initial");
|
|
131
|
-
await cache.set(key, "updated");
|
|
132
|
-
const result = await cache.get(key);
|
|
133
|
-
globalExpect(result).toBe("updated");
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe("delete", () => {
|
|
137
|
-
it("should delete existing key", async () => {
|
|
138
|
-
const key = getTestKey("delete-test");
|
|
139
|
-
await cache.set(key, "value-to-delete");
|
|
140
|
-
await cache.delete(key);
|
|
141
|
-
const result = await cache.get(key);
|
|
142
|
-
globalExpect(result).toBeUndefined();
|
|
143
|
-
});
|
|
144
|
-
it("should handle deletion of non-existent key", async () => {
|
|
145
|
-
const key = getTestKey("non-existent-delete");
|
|
146
|
-
await globalExpect(cache.delete(key)).resolves.not.toThrow();
|
|
147
|
-
});
|
|
148
|
-
it("should only delete specified key", async () => {
|
|
149
|
-
const key1 = getTestKey("delete-key1");
|
|
150
|
-
const key2 = getTestKey("delete-key2");
|
|
151
|
-
await cache.set(key1, "value1");
|
|
152
|
-
await cache.set(key2, "value2");
|
|
153
|
-
await cache.delete(key1);
|
|
154
|
-
globalExpect(await cache.get(key1)).toBeUndefined();
|
|
155
|
-
globalExpect(await cache.get(key2)).toBe("value2");
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe("integration scenarios", () => {
|
|
159
|
-
it("should handle round-trip operations", async () => {
|
|
160
|
-
const key = getTestKey("user-session");
|
|
161
|
-
const testData = {
|
|
162
|
-
user: {
|
|
163
|
-
id: 1,
|
|
164
|
-
name: "John"
|
|
165
|
-
},
|
|
166
|
-
preferences: ["dark-mode", "notifications"],
|
|
167
|
-
count: 42
|
|
168
|
-
};
|
|
169
|
-
await cache.set(key, testData);
|
|
170
|
-
const result = await cache.get(key);
|
|
171
|
-
globalExpect(result).toEqual(testData);
|
|
172
|
-
});
|
|
173
|
-
it("should handle complex nested objects", async () => {
|
|
174
|
-
const key = getTestKey("complex");
|
|
175
|
-
const complexObject = { level1: { level2: { level3: {
|
|
176
|
-
data: "deep nested value",
|
|
177
|
-
array: [{ id: 1 }, { id: 2 }]
|
|
178
|
-
} } } };
|
|
179
|
-
await cache.set(key, complexObject);
|
|
180
|
-
const result = await cache.get(key);
|
|
181
|
-
globalExpect(result).toEqual(complexObject);
|
|
182
|
-
});
|
|
183
|
-
it("should handle concurrent operations", async () => {
|
|
184
|
-
const keys = [
|
|
185
|
-
"concurrent1",
|
|
186
|
-
"concurrent2",
|
|
187
|
-
"concurrent3"
|
|
188
|
-
].map((suffix) => getTestKey(suffix));
|
|
189
|
-
const values = [
|
|
190
|
-
"value1",
|
|
191
|
-
"value2",
|
|
192
|
-
"value3"
|
|
193
|
-
];
|
|
194
|
-
await Promise.all(keys.map((key, i) => cache.set(key, values[i])));
|
|
195
|
-
const results = await Promise.all(keys.map((key) => cache.get(key)));
|
|
196
|
-
globalExpect(results).toEqual(values);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
//#endregion
|