@geekmidas/cache 0.0.1

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.
@@ -0,0 +1,76 @@
1
+ const require_memory = require('../memory-n6Iosq6J.cjs');
2
+ const require_upstash = require('../upstash-s7dedvpn.cjs');
3
+ const require_vi_DgezovHB = require('../vi.DgezovHB-NqP74KGR.cjs');
4
+
5
+ //#region src/__tests__/cache.spec.ts
6
+ require_vi_DgezovHB.describe("Cache Interface", () => {
7
+ require_vi_DgezovHB.describe("interface compliance", () => {
8
+ require_vi_DgezovHB.it("InMemoryCache should implement Cache interface", () => {
9
+ const cache = new require_memory.InMemoryCache();
10
+ require_vi_DgezovHB.globalExpect(typeof cache.get).toBe("function");
11
+ require_vi_DgezovHB.globalExpect(typeof cache.set).toBe("function");
12
+ require_vi_DgezovHB.globalExpect(typeof cache.delete).toBe("function");
13
+ });
14
+ require_vi_DgezovHB.it("UpstashCache should implement Cache interface", () => {
15
+ const cache = new require_upstash.UpstashCache("http://localhost:8079", "example_token");
16
+ require_vi_DgezovHB.globalExpect(typeof cache.get).toBe("function");
17
+ require_vi_DgezovHB.globalExpect(typeof cache.set).toBe("function");
18
+ require_vi_DgezovHB.globalExpect(typeof cache.delete).toBe("function");
19
+ });
20
+ });
21
+ require_vi_DgezovHB.describe("method signatures", () => {
22
+ require_vi_DgezovHB.it("should have correct get method signature", () => {
23
+ const cache = new require_memory.InMemoryCache();
24
+ const getResult = cache.get("test");
25
+ require_vi_DgezovHB.globalExpect(getResult).toBeInstanceOf(Promise);
26
+ });
27
+ require_vi_DgezovHB.it("should have correct set method signature", () => {
28
+ const cache = new require_memory.InMemoryCache();
29
+ const setResult = cache.set("test", "value");
30
+ require_vi_DgezovHB.globalExpect(setResult).toBeInstanceOf(Promise);
31
+ });
32
+ require_vi_DgezovHB.it("should have correct delete method signature", () => {
33
+ const cache = new require_memory.InMemoryCache();
34
+ const deleteResult = cache.delete("test");
35
+ require_vi_DgezovHB.globalExpect(deleteResult).toBeInstanceOf(Promise);
36
+ });
37
+ });
38
+ require_vi_DgezovHB.describe("generic type support", () => {
39
+ require_vi_DgezovHB.it("should support string types", async () => {
40
+ const cache = new require_memory.InMemoryCache();
41
+ await cache.set("key", "value");
42
+ const result = await cache.get("key");
43
+ require_vi_DgezovHB.globalExpect(typeof result === "string" || result === void 0).toBe(true);
44
+ });
45
+ require_vi_DgezovHB.it("should support number types", async () => {
46
+ const cache = new require_memory.InMemoryCache();
47
+ await cache.set("key", 42);
48
+ const result = await cache.get("key");
49
+ require_vi_DgezovHB.globalExpect(typeof result === "number" || result === void 0).toBe(true);
50
+ });
51
+ require_vi_DgezovHB.it("should support object types", async () => {
52
+ const cache = new require_memory.InMemoryCache();
53
+ const user = {
54
+ id: 1,
55
+ name: "John"
56
+ };
57
+ await cache.set("user", user);
58
+ const result = await cache.get("user");
59
+ require_vi_DgezovHB.globalExpect(result === void 0 || typeof result === "object" && "id" in result && "name" in result).toBe(true);
60
+ });
61
+ require_vi_DgezovHB.it("should support union types", async () => {
62
+ const cache = new require_memory.InMemoryCache();
63
+ await cache.set("string", "text");
64
+ await cache.set("number", 42);
65
+ await cache.set("boolean", true);
66
+ const stringResult = await cache.get("string");
67
+ const numberResult = await cache.get("number");
68
+ const booleanResult = await cache.get("boolean");
69
+ require_vi_DgezovHB.globalExpect(stringResult).toBe("text");
70
+ require_vi_DgezovHB.globalExpect(numberResult).toBe(42);
71
+ require_vi_DgezovHB.globalExpect(booleanResult).toBe(true);
72
+ });
73
+ });
74
+ });
75
+
76
+ //#endregion
@@ -0,0 +1,76 @@
1
+ import { describe, globalExpect, it } from "../vi.DgezovHB-McgltIC5.mjs";
2
+ import { InMemoryCache } from "../memory-YteQXj7m.mjs";
3
+ import { UpstashCache } from "../upstash-Cpe9W0-L.mjs";
4
+
5
+ //#region src/__tests__/cache.spec.ts
6
+ describe("Cache Interface", () => {
7
+ describe("interface compliance", () => {
8
+ it("InMemoryCache should implement Cache interface", () => {
9
+ const cache = new InMemoryCache();
10
+ globalExpect(typeof cache.get).toBe("function");
11
+ globalExpect(typeof cache.set).toBe("function");
12
+ globalExpect(typeof cache.delete).toBe("function");
13
+ });
14
+ it("UpstashCache should implement Cache interface", () => {
15
+ const cache = new UpstashCache("http://localhost:8079", "example_token");
16
+ globalExpect(typeof cache.get).toBe("function");
17
+ globalExpect(typeof cache.set).toBe("function");
18
+ globalExpect(typeof cache.delete).toBe("function");
19
+ });
20
+ });
21
+ describe("method signatures", () => {
22
+ it("should have correct get method signature", () => {
23
+ const cache = new InMemoryCache();
24
+ const getResult = cache.get("test");
25
+ globalExpect(getResult).toBeInstanceOf(Promise);
26
+ });
27
+ it("should have correct set method signature", () => {
28
+ const cache = new InMemoryCache();
29
+ const setResult = cache.set("test", "value");
30
+ globalExpect(setResult).toBeInstanceOf(Promise);
31
+ });
32
+ it("should have correct delete method signature", () => {
33
+ const cache = new InMemoryCache();
34
+ const deleteResult = cache.delete("test");
35
+ globalExpect(deleteResult).toBeInstanceOf(Promise);
36
+ });
37
+ });
38
+ describe("generic type support", () => {
39
+ it("should support string types", async () => {
40
+ const cache = new InMemoryCache();
41
+ await cache.set("key", "value");
42
+ const result = await cache.get("key");
43
+ globalExpect(typeof result === "string" || result === void 0).toBe(true);
44
+ });
45
+ it("should support number types", async () => {
46
+ const cache = new InMemoryCache();
47
+ await cache.set("key", 42);
48
+ const result = await cache.get("key");
49
+ globalExpect(typeof result === "number" || result === void 0).toBe(true);
50
+ });
51
+ it("should support object types", async () => {
52
+ const cache = new InMemoryCache();
53
+ const user = {
54
+ id: 1,
55
+ name: "John"
56
+ };
57
+ await cache.set("user", user);
58
+ const result = await cache.get("user");
59
+ globalExpect(result === void 0 || typeof result === "object" && "id" in result && "name" in result).toBe(true);
60
+ });
61
+ it("should support union types", async () => {
62
+ const cache = new InMemoryCache();
63
+ await cache.set("string", "text");
64
+ await cache.set("number", 42);
65
+ await cache.set("boolean", true);
66
+ const stringResult = await cache.get("string");
67
+ const numberResult = await cache.get("number");
68
+ const booleanResult = await cache.get("boolean");
69
+ globalExpect(stringResult).toBe("text");
70
+ globalExpect(numberResult).toBe(42);
71
+ globalExpect(booleanResult).toBe(true);
72
+ });
73
+ });
74
+ });
75
+
76
+ //#endregion
@@ -0,0 +1,234 @@
1
+ const require_memory = require('../memory-n6Iosq6J.cjs');
2
+ const require_vi_DgezovHB = require('../vi.DgezovHB-NqP74KGR.cjs');
3
+
4
+ //#region src/__tests__/integration.spec.ts
5
+ require_vi_DgezovHB.describe("Cache Integration Tests", () => {
6
+ let memoryCache;
7
+ require_vi_DgezovHB.beforeEach(() => {
8
+ memoryCache = new require_memory.InMemoryCache();
9
+ });
10
+ require_vi_DgezovHB.describe("cross-cache behavior consistency", () => {
11
+ const testCases = [{
12
+ name: "InMemoryCache",
13
+ cache: () => new require_memory.InMemoryCache()
14
+ }];
15
+ testCases.forEach(({ name, cache }) => {
16
+ require_vi_DgezovHB.describe(name, () => {
17
+ let cacheInstance;
18
+ require_vi_DgezovHB.beforeEach(() => {
19
+ cacheInstance = cache();
20
+ });
21
+ require_vi_DgezovHB.it("should handle basic CRUD operations", async () => {
22
+ await cacheInstance.set("user:1", {
23
+ id: 1,
24
+ name: "John"
25
+ });
26
+ const user = await cacheInstance.get("user:1");
27
+ require_vi_DgezovHB.globalExpect(user).toEqual({
28
+ id: 1,
29
+ name: "John"
30
+ });
31
+ await cacheInstance.set("user:1", {
32
+ id: 1,
33
+ name: "Jane"
34
+ });
35
+ const updatedUser = await cacheInstance.get("user:1");
36
+ require_vi_DgezovHB.globalExpect(updatedUser).toEqual({
37
+ id: 1,
38
+ name: "Jane"
39
+ });
40
+ await cacheInstance.delete("user:1");
41
+ const deletedUser = await cacheInstance.get("user:1");
42
+ require_vi_DgezovHB.globalExpect(deletedUser).toBeUndefined();
43
+ });
44
+ require_vi_DgezovHB.it("should handle concurrent operations", async () => {
45
+ const operations = [
46
+ cacheInstance.set("key1", "value1"),
47
+ cacheInstance.set("key2", "value2"),
48
+ cacheInstance.set("key3", "value3")
49
+ ];
50
+ await Promise.all(operations);
51
+ const results = await Promise.all([
52
+ cacheInstance.get("key1"),
53
+ cacheInstance.get("key2"),
54
+ cacheInstance.get("key3")
55
+ ]);
56
+ require_vi_DgezovHB.globalExpect(results).toEqual([
57
+ "value1",
58
+ "value2",
59
+ "value3"
60
+ ]);
61
+ });
62
+ require_vi_DgezovHB.it("should handle data type preservation", async () => {
63
+ const testData = {
64
+ string: "hello",
65
+ number: 42,
66
+ boolean: true,
67
+ object: { nested: true },
68
+ array: [
69
+ 1,
70
+ 2,
71
+ 3
72
+ ],
73
+ null: null
74
+ };
75
+ await Promise.all(Object.entries(testData).map(([key, value]) => cacheInstance.set(key, value)));
76
+ const results = await Promise.all(Object.keys(testData).map((key) => cacheInstance.get(key)));
77
+ require_vi_DgezovHB.globalExpect(results[0]).toBe("hello");
78
+ require_vi_DgezovHB.globalExpect(results[1]).toBe(42);
79
+ require_vi_DgezovHB.globalExpect(results[2]).toBe(true);
80
+ require_vi_DgezovHB.globalExpect(results[3]).toEqual({ nested: true });
81
+ require_vi_DgezovHB.globalExpect(results[4]).toEqual([
82
+ 1,
83
+ 2,
84
+ 3
85
+ ]);
86
+ require_vi_DgezovHB.globalExpect(results[5]).toBeNull();
87
+ });
88
+ require_vi_DgezovHB.it("should handle key isolation", async () => {
89
+ await cacheInstance.set("user:1", "User One");
90
+ await cacheInstance.set("user:2", "User Two");
91
+ await cacheInstance.set("session:1", "Session One");
92
+ await cacheInstance.delete("user:1");
93
+ require_vi_DgezovHB.globalExpect(await cacheInstance.get("user:1")).toBeUndefined();
94
+ require_vi_DgezovHB.globalExpect(await cacheInstance.get("user:2")).toBe("User Two");
95
+ require_vi_DgezovHB.globalExpect(await cacheInstance.get("session:1")).toBe("Session One");
96
+ });
97
+ });
98
+ });
99
+ });
100
+ require_vi_DgezovHB.describe("cache migration scenarios", () => {
101
+ require_vi_DgezovHB.it("should support migrating data between cache implementations", async () => {
102
+ const sourceCache = new require_memory.InMemoryCache();
103
+ const targetCache = new require_memory.InMemoryCache();
104
+ const testData = {
105
+ "user:1": {
106
+ id: 1,
107
+ name: "John"
108
+ },
109
+ "user:2": {
110
+ id: 2,
111
+ name: "Jane"
112
+ },
113
+ "config:app": {
114
+ theme: "dark",
115
+ notifications: true
116
+ }
117
+ };
118
+ for (const [key, value] of Object.entries(testData)) await sourceCache.set(key, value);
119
+ const migrationKeys = Object.keys(testData);
120
+ for (const key of migrationKeys) {
121
+ const value = await sourceCache.get(key);
122
+ if (value !== void 0) await targetCache.set(key, value);
123
+ }
124
+ for (const [key, expectedValue] of Object.entries(testData)) {
125
+ const migratedValue = await targetCache.get(key);
126
+ require_vi_DgezovHB.globalExpect(migratedValue).toEqual(expectedValue);
127
+ }
128
+ });
129
+ });
130
+ require_vi_DgezovHB.describe("cache abstraction patterns", () => {
131
+ require_vi_DgezovHB.it("should support cache factory pattern", async () => {
132
+ const createCache = (type) => {
133
+ switch (type) {
134
+ case "memory": return new require_memory.InMemoryCache();
135
+ default: throw new Error(`Unknown cache type: ${type}`);
136
+ }
137
+ };
138
+ const userCache = createCache("memory");
139
+ const sessionCache = createCache("memory");
140
+ await userCache.set("user:1", {
141
+ id: 1,
142
+ name: "John"
143
+ });
144
+ await sessionCache.set("session:abc", "active");
145
+ require_vi_DgezovHB.globalExpect(await userCache.get("user:1")).toEqual({
146
+ id: 1,
147
+ name: "John"
148
+ });
149
+ require_vi_DgezovHB.globalExpect(await sessionCache.get("session:abc")).toBe("active");
150
+ });
151
+ require_vi_DgezovHB.it("should support cache wrapper pattern", async () => {
152
+ class LoggingCache {
153
+ logs = [];
154
+ constructor(underlying) {
155
+ this.underlying = underlying;
156
+ }
157
+ async get(key) {
158
+ this.logs.push(`GET ${key}`);
159
+ return this.underlying.get(key);
160
+ }
161
+ async set(key, value) {
162
+ this.logs.push(`SET ${key}`);
163
+ return this.underlying.set(key, value);
164
+ }
165
+ async delete(key) {
166
+ this.logs.push(`DELETE ${key}`);
167
+ return this.underlying.delete(key);
168
+ }
169
+ getLogs() {
170
+ return [...this.logs];
171
+ }
172
+ }
173
+ const baseCache = new require_memory.InMemoryCache();
174
+ const loggingCache = new LoggingCache(baseCache);
175
+ await loggingCache.set("test", "value");
176
+ await loggingCache.get("test");
177
+ await loggingCache.delete("test");
178
+ const logs = loggingCache.getLogs();
179
+ require_vi_DgezovHB.globalExpect(logs).toEqual([
180
+ "SET test",
181
+ "GET test",
182
+ "DELETE test"
183
+ ]);
184
+ });
185
+ });
186
+ require_vi_DgezovHB.describe("performance and stress tests", () => {
187
+ require_vi_DgezovHB.it("should handle large number of operations", async () => {
188
+ const cache = new require_memory.InMemoryCache();
189
+ const operationCount = 1e3;
190
+ const insertPromises = Array.from({ length: operationCount }, (_, i) => cache.set(`key:${i}`, i));
191
+ await Promise.all(insertPromises);
192
+ const readPromises = Array.from({ length: operationCount }, (_, i) => cache.get(`key:${i}`));
193
+ const results = await Promise.all(readPromises);
194
+ for (let i = 0; i < operationCount; i++) require_vi_DgezovHB.globalExpect(results[i]).toBe(i);
195
+ const deletePromises = Array.from({ length: operationCount }, (_, i) => cache.delete(`key:${i}`));
196
+ await Promise.all(deletePromises);
197
+ const postDeleteRead = await cache.get("key:0");
198
+ require_vi_DgezovHB.globalExpect(postDeleteRead).toBeUndefined();
199
+ });
200
+ require_vi_DgezovHB.it("should handle large objects efficiently", async () => {
201
+ const cache = new require_memory.InMemoryCache();
202
+ const largeObject = {
203
+ id: 1,
204
+ data: Array.from({ length: 1e3 }, (_, i) => ({
205
+ index: i,
206
+ value: `value-${i}`,
207
+ metadata: {
208
+ timestamp: Date.now(),
209
+ random: Math.random()
210
+ }
211
+ }))
212
+ };
213
+ const startTime = Date.now();
214
+ await cache.set("large-object", largeObject);
215
+ const result = await cache.get("large-object");
216
+ const endTime = Date.now();
217
+ require_vi_DgezovHB.globalExpect(result).toEqual(largeObject);
218
+ require_vi_DgezovHB.globalExpect(endTime - startTime).toBeLessThan(100);
219
+ });
220
+ });
221
+ require_vi_DgezovHB.describe("error scenarios", () => {
222
+ require_vi_DgezovHB.it("should handle operations after errors gracefully", async () => {
223
+ const cache = new require_memory.InMemoryCache();
224
+ await cache.set("valid-key", "valid-value");
225
+ require_vi_DgezovHB.globalExpect(await cache.get("valid-key")).toBe("valid-value");
226
+ await cache.set("another-key", "another-value");
227
+ require_vi_DgezovHB.globalExpect(await cache.get("another-key")).toBe("another-value");
228
+ await cache.delete("valid-key");
229
+ require_vi_DgezovHB.globalExpect(await cache.get("valid-key")).toBeUndefined();
230
+ });
231
+ });
232
+ });
233
+
234
+ //#endregion
@@ -0,0 +1,234 @@
1
+ import { beforeEach, describe, globalExpect, it } from "../vi.DgezovHB-McgltIC5.mjs";
2
+ import { InMemoryCache } from "../memory-YteQXj7m.mjs";
3
+
4
+ //#region src/__tests__/integration.spec.ts
5
+ describe("Cache Integration Tests", () => {
6
+ let memoryCache;
7
+ beforeEach(() => {
8
+ memoryCache = new InMemoryCache();
9
+ });
10
+ describe("cross-cache behavior consistency", () => {
11
+ const testCases = [{
12
+ name: "InMemoryCache",
13
+ cache: () => new InMemoryCache()
14
+ }];
15
+ testCases.forEach(({ name, cache }) => {
16
+ describe(name, () => {
17
+ let cacheInstance;
18
+ beforeEach(() => {
19
+ cacheInstance = cache();
20
+ });
21
+ it("should handle basic CRUD operations", async () => {
22
+ await cacheInstance.set("user:1", {
23
+ id: 1,
24
+ name: "John"
25
+ });
26
+ const user = await cacheInstance.get("user:1");
27
+ globalExpect(user).toEqual({
28
+ id: 1,
29
+ name: "John"
30
+ });
31
+ await cacheInstance.set("user:1", {
32
+ id: 1,
33
+ name: "Jane"
34
+ });
35
+ const updatedUser = await cacheInstance.get("user:1");
36
+ globalExpect(updatedUser).toEqual({
37
+ id: 1,
38
+ name: "Jane"
39
+ });
40
+ await cacheInstance.delete("user:1");
41
+ const deletedUser = await cacheInstance.get("user:1");
42
+ globalExpect(deletedUser).toBeUndefined();
43
+ });
44
+ it("should handle concurrent operations", async () => {
45
+ const operations = [
46
+ cacheInstance.set("key1", "value1"),
47
+ cacheInstance.set("key2", "value2"),
48
+ cacheInstance.set("key3", "value3")
49
+ ];
50
+ await Promise.all(operations);
51
+ const results = await Promise.all([
52
+ cacheInstance.get("key1"),
53
+ cacheInstance.get("key2"),
54
+ cacheInstance.get("key3")
55
+ ]);
56
+ globalExpect(results).toEqual([
57
+ "value1",
58
+ "value2",
59
+ "value3"
60
+ ]);
61
+ });
62
+ it("should handle data type preservation", async () => {
63
+ const testData = {
64
+ string: "hello",
65
+ number: 42,
66
+ boolean: true,
67
+ object: { nested: true },
68
+ array: [
69
+ 1,
70
+ 2,
71
+ 3
72
+ ],
73
+ null: null
74
+ };
75
+ await Promise.all(Object.entries(testData).map(([key, value]) => cacheInstance.set(key, value)));
76
+ const results = await Promise.all(Object.keys(testData).map((key) => cacheInstance.get(key)));
77
+ globalExpect(results[0]).toBe("hello");
78
+ globalExpect(results[1]).toBe(42);
79
+ globalExpect(results[2]).toBe(true);
80
+ globalExpect(results[3]).toEqual({ nested: true });
81
+ globalExpect(results[4]).toEqual([
82
+ 1,
83
+ 2,
84
+ 3
85
+ ]);
86
+ globalExpect(results[5]).toBeNull();
87
+ });
88
+ it("should handle key isolation", async () => {
89
+ await cacheInstance.set("user:1", "User One");
90
+ await cacheInstance.set("user:2", "User Two");
91
+ await cacheInstance.set("session:1", "Session One");
92
+ await cacheInstance.delete("user:1");
93
+ globalExpect(await cacheInstance.get("user:1")).toBeUndefined();
94
+ globalExpect(await cacheInstance.get("user:2")).toBe("User Two");
95
+ globalExpect(await cacheInstance.get("session:1")).toBe("Session One");
96
+ });
97
+ });
98
+ });
99
+ });
100
+ describe("cache migration scenarios", () => {
101
+ it("should support migrating data between cache implementations", async () => {
102
+ const sourceCache = new InMemoryCache();
103
+ const targetCache = new InMemoryCache();
104
+ const testData = {
105
+ "user:1": {
106
+ id: 1,
107
+ name: "John"
108
+ },
109
+ "user:2": {
110
+ id: 2,
111
+ name: "Jane"
112
+ },
113
+ "config:app": {
114
+ theme: "dark",
115
+ notifications: true
116
+ }
117
+ };
118
+ for (const [key, value] of Object.entries(testData)) await sourceCache.set(key, value);
119
+ const migrationKeys = Object.keys(testData);
120
+ for (const key of migrationKeys) {
121
+ const value = await sourceCache.get(key);
122
+ if (value !== void 0) await targetCache.set(key, value);
123
+ }
124
+ for (const [key, expectedValue] of Object.entries(testData)) {
125
+ const migratedValue = await targetCache.get(key);
126
+ globalExpect(migratedValue).toEqual(expectedValue);
127
+ }
128
+ });
129
+ });
130
+ describe("cache abstraction patterns", () => {
131
+ it("should support cache factory pattern", async () => {
132
+ const createCache = (type) => {
133
+ switch (type) {
134
+ case "memory": return new InMemoryCache();
135
+ default: throw new Error(`Unknown cache type: ${type}`);
136
+ }
137
+ };
138
+ const userCache = createCache("memory");
139
+ const sessionCache = createCache("memory");
140
+ await userCache.set("user:1", {
141
+ id: 1,
142
+ name: "John"
143
+ });
144
+ await sessionCache.set("session:abc", "active");
145
+ globalExpect(await userCache.get("user:1")).toEqual({
146
+ id: 1,
147
+ name: "John"
148
+ });
149
+ globalExpect(await sessionCache.get("session:abc")).toBe("active");
150
+ });
151
+ it("should support cache wrapper pattern", async () => {
152
+ class LoggingCache {
153
+ logs = [];
154
+ constructor(underlying) {
155
+ this.underlying = underlying;
156
+ }
157
+ async get(key) {
158
+ this.logs.push(`GET ${key}`);
159
+ return this.underlying.get(key);
160
+ }
161
+ async set(key, value) {
162
+ this.logs.push(`SET ${key}`);
163
+ return this.underlying.set(key, value);
164
+ }
165
+ async delete(key) {
166
+ this.logs.push(`DELETE ${key}`);
167
+ return this.underlying.delete(key);
168
+ }
169
+ getLogs() {
170
+ return [...this.logs];
171
+ }
172
+ }
173
+ const baseCache = new InMemoryCache();
174
+ const loggingCache = new LoggingCache(baseCache);
175
+ await loggingCache.set("test", "value");
176
+ await loggingCache.get("test");
177
+ await loggingCache.delete("test");
178
+ const logs = loggingCache.getLogs();
179
+ globalExpect(logs).toEqual([
180
+ "SET test",
181
+ "GET test",
182
+ "DELETE test"
183
+ ]);
184
+ });
185
+ });
186
+ describe("performance and stress tests", () => {
187
+ it("should handle large number of operations", async () => {
188
+ const cache = new InMemoryCache();
189
+ const operationCount = 1e3;
190
+ const insertPromises = Array.from({ length: operationCount }, (_, i) => cache.set(`key:${i}`, i));
191
+ await Promise.all(insertPromises);
192
+ const readPromises = Array.from({ length: operationCount }, (_, i) => cache.get(`key:${i}`));
193
+ const results = await Promise.all(readPromises);
194
+ for (let i = 0; i < operationCount; i++) globalExpect(results[i]).toBe(i);
195
+ const deletePromises = Array.from({ length: operationCount }, (_, i) => cache.delete(`key:${i}`));
196
+ await Promise.all(deletePromises);
197
+ const postDeleteRead = await cache.get("key:0");
198
+ globalExpect(postDeleteRead).toBeUndefined();
199
+ });
200
+ it("should handle large objects efficiently", async () => {
201
+ const cache = new InMemoryCache();
202
+ const largeObject = {
203
+ id: 1,
204
+ data: Array.from({ length: 1e3 }, (_, i) => ({
205
+ index: i,
206
+ value: `value-${i}`,
207
+ metadata: {
208
+ timestamp: Date.now(),
209
+ random: Math.random()
210
+ }
211
+ }))
212
+ };
213
+ const startTime = Date.now();
214
+ await cache.set("large-object", largeObject);
215
+ const result = await cache.get("large-object");
216
+ const endTime = Date.now();
217
+ globalExpect(result).toEqual(largeObject);
218
+ globalExpect(endTime - startTime).toBeLessThan(100);
219
+ });
220
+ });
221
+ describe("error scenarios", () => {
222
+ it("should handle operations after errors gracefully", async () => {
223
+ const cache = new InMemoryCache();
224
+ await cache.set("valid-key", "valid-value");
225
+ globalExpect(await cache.get("valid-key")).toBe("valid-value");
226
+ await cache.set("another-key", "another-value");
227
+ globalExpect(await cache.get("another-key")).toBe("another-value");
228
+ await cache.delete("valid-key");
229
+ globalExpect(await cache.get("valid-key")).toBeUndefined();
230
+ });
231
+ });
232
+ });
233
+
234
+ //#endregion