@geekmidas/cache 0.0.7 → 0.2.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.
Files changed (73) hide show
  1. package/dist/{chunk-DWy1uDak.cjs → chunk-CUT6urMc.cjs} +0 -9
  2. package/dist/expo.cjs +4 -3
  3. package/dist/expo.cjs.map +1 -0
  4. package/dist/expo.d.cts +8 -5
  5. package/dist/expo.d.cts.map +1 -0
  6. package/dist/expo.d.mts +8 -5
  7. package/dist/expo.d.mts.map +1 -0
  8. package/dist/expo.mjs +3 -2
  9. package/dist/expo.mjs.map +1 -0
  10. package/dist/{index-B6eF5Yxi.d.cts → index-BSYYdwRm.d.cts} +8 -5
  11. package/dist/index-BSYYdwRm.d.cts.map +1 -0
  12. package/dist/{index-Bv61mxVT.d.mts → index-Dx96gr-9.d.mts} +8 -5
  13. package/dist/index-Dx96gr-9.d.mts.map +1 -0
  14. package/dist/index.cjs +1 -1
  15. package/dist/index.d.cts +1 -1
  16. package/dist/index.d.mts +1 -1
  17. package/dist/index.mjs +1 -1
  18. package/dist/memory.cjs +35 -3
  19. package/dist/memory.cjs.map +1 -0
  20. package/dist/memory.d.cts +8 -5
  21. package/dist/memory.d.cts.map +1 -0
  22. package/dist/memory.d.mts +8 -5
  23. package/dist/memory.d.mts.map +1 -0
  24. package/dist/memory.mjs +34 -3
  25. package/dist/memory.mjs.map +1 -0
  26. package/dist/{src-DVpoP03o.mjs → src-CrE4Nl5T.mjs} +2 -1
  27. package/dist/src-CrE4Nl5T.mjs.map +1 -0
  28. package/dist/{src-C7d6HaTp.cjs → src-zfYb7mdS.cjs} +3 -2
  29. package/dist/src-zfYb7mdS.cjs.map +1 -0
  30. package/dist/upstash.cjs +32 -2
  31. package/dist/upstash.cjs.map +1 -0
  32. package/dist/upstash.d.cts +8 -5
  33. package/dist/upstash.d.cts.map +1 -0
  34. package/dist/upstash.d.mts +8 -5
  35. package/dist/upstash.d.mts.map +1 -0
  36. package/dist/upstash.mjs +31 -2
  37. package/dist/upstash.mjs.map +1 -0
  38. package/package.json +6 -2
  39. package/src/__benchmarks__/memory.bench.ts +51 -0
  40. package/src/__tests__/cache.spec.ts +138 -105
  41. package/src/__tests__/integration.spec.ts +277 -268
  42. package/src/__tests__/memory.spec.ts +129 -129
  43. package/src/__tests__/upstash.spec.ts +209 -180
  44. package/src/expo.ts +45 -46
  45. package/src/index.ts +37 -36
  46. package/src/memory.ts +28 -27
  47. package/src/upstash.ts +28 -28
  48. package/tsconfig.json +9 -0
  49. package/tsdown.config.ts +1 -1
  50. package/dist/__tests__/cache.spec.cjs +0 -77
  51. package/dist/__tests__/cache.spec.d.cts +0 -1
  52. package/dist/__tests__/cache.spec.d.mts +0 -1
  53. package/dist/__tests__/cache.spec.mjs +0 -77
  54. package/dist/__tests__/integration.spec.cjs +0 -235
  55. package/dist/__tests__/integration.spec.d.cts +0 -1
  56. package/dist/__tests__/integration.spec.d.mts +0 -1
  57. package/dist/__tests__/integration.spec.mjs +0 -235
  58. package/dist/__tests__/memory.spec.cjs +0 -126
  59. package/dist/__tests__/memory.spec.d.cts +0 -1
  60. package/dist/__tests__/memory.spec.d.mts +0 -1
  61. package/dist/__tests__/memory.spec.mjs +0 -126
  62. package/dist/__tests__/upstash.spec.cjs +0 -201
  63. package/dist/__tests__/upstash.spec.d.cts +0 -1
  64. package/dist/__tests__/upstash.spec.d.mts +0 -1
  65. package/dist/__tests__/upstash.spec.mjs +0 -201
  66. package/dist/magic-string.es-CBih0MJw.mjs +0 -1014
  67. package/dist/magic-string.es-KiPEzMtt.cjs +0 -1015
  68. package/dist/memory-Csy6J-Ak.cjs +0 -39
  69. package/dist/memory-QDTnSEX5.mjs +0 -33
  70. package/dist/upstash-CXy_duOa.mjs +0 -31
  71. package/dist/upstash-u8Hs4sZG.cjs +0 -37
  72. package/dist/vi.bdSIJ99Y-B-qkABPq.cjs +0 -14955
  73. package/dist/vi.bdSIJ99Y-CB5havZF.mjs +0 -14951
package/src/memory.ts CHANGED
@@ -1,37 +1,38 @@
1
1
  import { addSeconds } from 'date-fns';
2
2
  import { type Cache, getExpirationInSeconds } from './';
3
3
 
4
- export class InMemoryCache<T> implements Cache<T> {
5
- private store: Map<string, T> = new Map();
6
- private expirations: Map<string, Date> = new Map();
4
+ export class InMemoryCache implements Cache {
5
+ private store: Map<string, unknown> = new Map();
6
+ private expirations: Map<string, Date> = new Map();
7
7
 
8
- async get(key: string): Promise<T | undefined> {
9
- const expiration = await this.ttl(key);
10
- if (!expiration) {
11
- await this.delete(key);
12
- return undefined;
13
- }
8
+ async get<T>(key: string): Promise<T | undefined> {
9
+ const expiration = await this.ttl(key);
10
+ if (!expiration) {
11
+ await this.delete(key);
12
+ return undefined;
13
+ }
14
14
 
15
- return this.store.get(key);
16
- }
15
+ return this.store.get(key) as T | undefined;
16
+ }
17
17
 
18
- async ttl(key: string): Promise<number> {
19
- const expiration = this.expirations.get(key);
20
- if (!expiration) {
21
- return 0;
22
- }
18
+ async ttl(key: string): Promise<number> {
19
+ const expiration = this.expirations.get(key);
20
+ if (!expiration) {
21
+ return 0;
22
+ }
23
23
 
24
- return getExpirationInSeconds(expiration);
25
- }
24
+ return getExpirationInSeconds(expiration);
25
+ }
26
26
 
27
- async set(key: string, value: T, ttl: number = 600): Promise<void> {
28
- this.store.set(key, value);
29
- const now = new Date();
30
- const expiresAt = addSeconds(now, ttl);
31
- this.expirations.set(key, expiresAt);
32
- }
27
+ async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {
28
+ this.store.set(key, value);
29
+ const now = new Date();
30
+ const expiresAt = addSeconds(now, ttl);
31
+ this.expirations.set(key, expiresAt);
32
+ }
33
33
 
34
- async delete(key: string): Promise<void> {
35
- this.store.delete(key);
36
- }
34
+ async delete(key: string): Promise<void> {
35
+ this.store.delete(key);
36
+ this.expirations.delete(key);
37
+ }
37
38
  }
package/src/upstash.ts CHANGED
@@ -1,41 +1,41 @@
1
1
  import { Redis } from '@upstash/redis';
2
2
  import type { Cache } from './';
3
3
 
4
- export class UpstashCache<T> implements Cache<T> {
5
- private client: Redis;
4
+ export class UpstashCache implements Cache {
5
+ private client: Redis;
6
6
 
7
- constructor(url: string, token: string) {
8
- this.client = new Redis({
9
- url,
10
- token,
11
- });
12
- }
7
+ constructor(url: string, token: string) {
8
+ this.client = new Redis({
9
+ url,
10
+ token,
11
+ });
12
+ }
13
13
 
14
- async ttl(key: string): Promise<number> {
15
- const ttl = await this.client.ttl(key);
14
+ async ttl(key: string): Promise<number> {
15
+ const ttl = await this.client.ttl(key);
16
16
 
17
- if (ttl === -2) {
18
- return 0; // Key does not exist
19
- }
17
+ if (ttl === -2) {
18
+ return 0; // Key does not exist
19
+ }
20
20
 
21
- return ttl; // Returns TTL in seconds
22
- }
21
+ return ttl; // Returns TTL in seconds
22
+ }
23
23
 
24
- async get(key: string): Promise<T | undefined> {
25
- const v = await this.client.get(key);
24
+ async get<T>(key: string): Promise<T | undefined> {
25
+ const v = await this.client.get(key);
26
26
 
27
- if (v === null) {
28
- return undefined;
29
- }
27
+ if (v === null) {
28
+ return undefined;
29
+ }
30
30
 
31
- return v as T; // Assuming the value is stored as a string, you may need to parse it if it's JSON
32
- }
31
+ return v as T;
32
+ }
33
33
 
34
- async set(key: string, value: T, ttl = 3600): Promise<void> {
35
- await this.client.set(key, value, { ex: ttl });
36
- }
34
+ async set<T>(key: string, value: T, ttl = 3600): Promise<void> {
35
+ await this.client.set(key, value, { ex: ttl });
36
+ }
37
37
 
38
- async delete(key: string): Promise<void> {
39
- await this.client.del(key);
40
- }
38
+ async delete(key: string): Promise<void> {
39
+ await this.client.del(key);
40
+ }
41
41
  }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "composite": true
7
+ },
8
+ "include": ["src/**/*"]
9
+ }
package/tsdown.config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from 'tsdown';
2
2
 
3
3
  export default defineConfig({
4
- external: ['expo-secure-store', '@upstash/redis'],
4
+ external: ['expo-secure-store', '@upstash/redis'],
5
5
  });
@@ -1,77 +0,0 @@
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
-
6
- //#region src/__tests__/cache.spec.ts
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
- const cache = new require_memory.InMemoryCache();
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
- });
15
- require_vi_bdSIJ99Y.it("UpstashCache should implement Cache interface", () => {
16
- const cache = new require_upstash.UpstashCache("http://localhost:8079", "example_token");
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
- });
21
- });
22
- require_vi_bdSIJ99Y.describe("method signatures", () => {
23
- require_vi_bdSIJ99Y.it("should have correct get method signature", () => {
24
- const cache = new require_memory.InMemoryCache();
25
- const getResult = cache.get("test");
26
- require_vi_bdSIJ99Y.globalExpect(getResult).toBeInstanceOf(Promise);
27
- });
28
- require_vi_bdSIJ99Y.it("should have correct set method signature", () => {
29
- const cache = new require_memory.InMemoryCache();
30
- const setResult = cache.set("test", "value");
31
- require_vi_bdSIJ99Y.globalExpect(setResult).toBeInstanceOf(Promise);
32
- });
33
- require_vi_bdSIJ99Y.it("should have correct delete method signature", () => {
34
- const cache = new require_memory.InMemoryCache();
35
- const deleteResult = cache.delete("test");
36
- require_vi_bdSIJ99Y.globalExpect(deleteResult).toBeInstanceOf(Promise);
37
- });
38
- });
39
- require_vi_bdSIJ99Y.describe("generic type support", () => {
40
- require_vi_bdSIJ99Y.it("should support string types", async () => {
41
- const cache = new require_memory.InMemoryCache();
42
- await cache.set("key", "value");
43
- const result = await cache.get("key");
44
- require_vi_bdSIJ99Y.globalExpect(typeof result === "string" || result === void 0).toBe(true);
45
- });
46
- require_vi_bdSIJ99Y.it("should support number types", async () => {
47
- const cache = new require_memory.InMemoryCache();
48
- await cache.set("key", 42);
49
- const result = await cache.get("key");
50
- require_vi_bdSIJ99Y.globalExpect(typeof result === "number" || result === void 0).toBe(true);
51
- });
52
- require_vi_bdSIJ99Y.it("should support object types", async () => {
53
- const cache = new require_memory.InMemoryCache();
54
- const user = {
55
- id: 1,
56
- name: "John"
57
- };
58
- await cache.set("user", user);
59
- const result = await cache.get("user");
60
- require_vi_bdSIJ99Y.globalExpect(result === void 0 || typeof result === "object" && "id" in result && "name" in result).toBe(true);
61
- });
62
- require_vi_bdSIJ99Y.it("should support union types", async () => {
63
- const cache = new require_memory.InMemoryCache();
64
- await cache.set("string", "text");
65
- await cache.set("number", 42);
66
- await cache.set("boolean", true);
67
- const stringResult = await cache.get("string");
68
- const numberResult = await cache.get("number");
69
- const booleanResult = await cache.get("boolean");
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
- });
74
- });
75
- });
76
-
77
- //#endregion
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1,77 +0,0 @@
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";
5
-
6
- //#region src/__tests__/cache.spec.ts
7
- describe("Cache Interface", () => {
8
- describe("interface compliance", () => {
9
- it("InMemoryCache should implement Cache interface", () => {
10
- const cache = new InMemoryCache();
11
- globalExpect(typeof cache.get).toBe("function");
12
- globalExpect(typeof cache.set).toBe("function");
13
- globalExpect(typeof cache.delete).toBe("function");
14
- });
15
- it("UpstashCache should implement Cache interface", () => {
16
- const cache = new UpstashCache("http://localhost:8079", "example_token");
17
- globalExpect(typeof cache.get).toBe("function");
18
- globalExpect(typeof cache.set).toBe("function");
19
- globalExpect(typeof cache.delete).toBe("function");
20
- });
21
- });
22
- describe("method signatures", () => {
23
- it("should have correct get method signature", () => {
24
- const cache = new InMemoryCache();
25
- const getResult = cache.get("test");
26
- globalExpect(getResult).toBeInstanceOf(Promise);
27
- });
28
- it("should have correct set method signature", () => {
29
- const cache = new InMemoryCache();
30
- const setResult = cache.set("test", "value");
31
- globalExpect(setResult).toBeInstanceOf(Promise);
32
- });
33
- it("should have correct delete method signature", () => {
34
- const cache = new InMemoryCache();
35
- const deleteResult = cache.delete("test");
36
- globalExpect(deleteResult).toBeInstanceOf(Promise);
37
- });
38
- });
39
- describe("generic type support", () => {
40
- it("should support string types", async () => {
41
- const cache = new InMemoryCache();
42
- await cache.set("key", "value");
43
- const result = await cache.get("key");
44
- globalExpect(typeof result === "string" || result === void 0).toBe(true);
45
- });
46
- it("should support number types", async () => {
47
- const cache = new InMemoryCache();
48
- await cache.set("key", 42);
49
- const result = await cache.get("key");
50
- globalExpect(typeof result === "number" || result === void 0).toBe(true);
51
- });
52
- it("should support object types", async () => {
53
- const cache = new InMemoryCache();
54
- const user = {
55
- id: 1,
56
- name: "John"
57
- };
58
- await cache.set("user", user);
59
- const result = await cache.get("user");
60
- globalExpect(result === void 0 || typeof result === "object" && "id" in result && "name" in result).toBe(true);
61
- });
62
- it("should support union types", async () => {
63
- const cache = new InMemoryCache();
64
- await cache.set("string", "text");
65
- await cache.set("number", 42);
66
- await cache.set("boolean", true);
67
- const stringResult = await cache.get("string");
68
- const numberResult = await cache.get("number");
69
- const booleanResult = await cache.get("boolean");
70
- globalExpect(stringResult).toBe("text");
71
- globalExpect(numberResult).toBe(42);
72
- globalExpect(booleanResult).toBe(true);
73
- });
74
- });
75
- });
76
-
77
- //#endregion
@@ -1,235 +0,0 @@
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
-
5
- //#region src/__tests__/integration.spec.ts
6
- require_vi_bdSIJ99Y.describe("Cache Integration Tests", () => {
7
- let memoryCache;
8
- require_vi_bdSIJ99Y.beforeEach(() => {
9
- memoryCache = new require_memory.InMemoryCache();
10
- });
11
- require_vi_bdSIJ99Y.describe("cross-cache behavior consistency", () => {
12
- const testCases = [{
13
- name: "InMemoryCache",
14
- cache: () => new require_memory.InMemoryCache()
15
- }];
16
- testCases.forEach(({ name, cache }) => {
17
- require_vi_bdSIJ99Y.describe(name, () => {
18
- let cacheInstance;
19
- require_vi_bdSIJ99Y.beforeEach(() => {
20
- cacheInstance = cache();
21
- });
22
- require_vi_bdSIJ99Y.it("should handle basic CRUD operations", async () => {
23
- await cacheInstance.set("user:1", {
24
- id: 1,
25
- name: "John"
26
- });
27
- const user = await cacheInstance.get("user:1");
28
- require_vi_bdSIJ99Y.globalExpect(user).toEqual({
29
- id: 1,
30
- name: "John"
31
- });
32
- await cacheInstance.set("user:1", {
33
- id: 1,
34
- name: "Jane"
35
- });
36
- const updatedUser = await cacheInstance.get("user:1");
37
- require_vi_bdSIJ99Y.globalExpect(updatedUser).toEqual({
38
- id: 1,
39
- name: "Jane"
40
- });
41
- await cacheInstance.delete("user:1");
42
- const deletedUser = await cacheInstance.get("user:1");
43
- require_vi_bdSIJ99Y.globalExpect(deletedUser).toBeUndefined();
44
- });
45
- require_vi_bdSIJ99Y.it("should handle concurrent operations", async () => {
46
- const operations = [
47
- cacheInstance.set("key1", "value1"),
48
- cacheInstance.set("key2", "value2"),
49
- cacheInstance.set("key3", "value3")
50
- ];
51
- await Promise.all(operations);
52
- const results = await Promise.all([
53
- cacheInstance.get("key1"),
54
- cacheInstance.get("key2"),
55
- cacheInstance.get("key3")
56
- ]);
57
- require_vi_bdSIJ99Y.globalExpect(results).toEqual([
58
- "value1",
59
- "value2",
60
- "value3"
61
- ]);
62
- });
63
- require_vi_bdSIJ99Y.it("should handle data type preservation", async () => {
64
- const testData = {
65
- string: "hello",
66
- number: 42,
67
- boolean: true,
68
- object: { nested: true },
69
- array: [
70
- 1,
71
- 2,
72
- 3
73
- ],
74
- null: null
75
- };
76
- await Promise.all(Object.entries(testData).map(([key, value]) => cacheInstance.set(key, value)));
77
- const results = await Promise.all(Object.keys(testData).map((key) => cacheInstance.get(key)));
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
- 1,
84
- 2,
85
- 3
86
- ]);
87
- require_vi_bdSIJ99Y.globalExpect(results[5]).toBeNull();
88
- });
89
- require_vi_bdSIJ99Y.it("should handle key isolation", async () => {
90
- await cacheInstance.set("user:1", "User One");
91
- await cacheInstance.set("user:2", "User Two");
92
- await cacheInstance.set("session:1", "Session One");
93
- await cacheInstance.delete("user:1");
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
- });
98
- });
99
- });
100
- });
101
- require_vi_bdSIJ99Y.describe("cache migration scenarios", () => {
102
- require_vi_bdSIJ99Y.it("should support migrating data between cache implementations", async () => {
103
- const sourceCache = new require_memory.InMemoryCache();
104
- const targetCache = new require_memory.InMemoryCache();
105
- const testData = {
106
- "user:1": {
107
- id: 1,
108
- name: "John"
109
- },
110
- "user:2": {
111
- id: 2,
112
- name: "Jane"
113
- },
114
- "config:app": {
115
- theme: "dark",
116
- notifications: true
117
- }
118
- };
119
- for (const [key, value] of Object.entries(testData)) await sourceCache.set(key, value);
120
- const migrationKeys = Object.keys(testData);
121
- for (const key of migrationKeys) {
122
- const value = await sourceCache.get(key);
123
- if (value !== void 0) await targetCache.set(key, value);
124
- }
125
- for (const [key, expectedValue] of Object.entries(testData)) {
126
- const migratedValue = await targetCache.get(key);
127
- require_vi_bdSIJ99Y.globalExpect(migratedValue).toEqual(expectedValue);
128
- }
129
- });
130
- });
131
- require_vi_bdSIJ99Y.describe("cache abstraction patterns", () => {
132
- require_vi_bdSIJ99Y.it("should support cache factory pattern", async () => {
133
- const createCache = (type) => {
134
- switch (type) {
135
- case "memory": return new require_memory.InMemoryCache();
136
- default: throw new Error(`Unknown cache type: ${type}`);
137
- }
138
- };
139
- const userCache = createCache("memory");
140
- const sessionCache = createCache("memory");
141
- await userCache.set("user:1", {
142
- id: 1,
143
- name: "John"
144
- });
145
- await sessionCache.set("session:abc", "active");
146
- require_vi_bdSIJ99Y.globalExpect(await userCache.get("user:1")).toEqual({
147
- id: 1,
148
- name: "John"
149
- });
150
- require_vi_bdSIJ99Y.globalExpect(await sessionCache.get("session:abc")).toBe("active");
151
- });
152
- require_vi_bdSIJ99Y.it("should support cache wrapper pattern", async () => {
153
- class LoggingCache {
154
- logs = [];
155
- constructor(underlying) {
156
- this.underlying = underlying;
157
- }
158
- async get(key) {
159
- this.logs.push(`GET ${key}`);
160
- return this.underlying.get(key);
161
- }
162
- async set(key, value) {
163
- this.logs.push(`SET ${key}`);
164
- return this.underlying.set(key, value);
165
- }
166
- async delete(key) {
167
- this.logs.push(`DELETE ${key}`);
168
- return this.underlying.delete(key);
169
- }
170
- getLogs() {
171
- return [...this.logs];
172
- }
173
- }
174
- const baseCache = new require_memory.InMemoryCache();
175
- const loggingCache = new LoggingCache(baseCache);
176
- await loggingCache.set("test", "value");
177
- await loggingCache.get("test");
178
- await loggingCache.delete("test");
179
- const logs = loggingCache.getLogs();
180
- require_vi_bdSIJ99Y.globalExpect(logs).toEqual([
181
- "SET test",
182
- "GET test",
183
- "DELETE test"
184
- ]);
185
- });
186
- });
187
- require_vi_bdSIJ99Y.describe("performance and stress tests", () => {
188
- require_vi_bdSIJ99Y.it("should handle large number of operations", async () => {
189
- const cache = new require_memory.InMemoryCache();
190
- const operationCount = 1e3;
191
- const insertPromises = Array.from({ length: operationCount }, (_, i) => cache.set(`key:${i}`, i));
192
- await Promise.all(insertPromises);
193
- const readPromises = Array.from({ length: operationCount }, (_, i) => cache.get(`key:${i}`));
194
- const results = await Promise.all(readPromises);
195
- for (let i = 0; i < operationCount; i++) require_vi_bdSIJ99Y.globalExpect(results[i]).toBe(i);
196
- const deletePromises = Array.from({ length: operationCount }, (_, i) => cache.delete(`key:${i}`));
197
- await Promise.all(deletePromises);
198
- const postDeleteRead = await cache.get("key:0");
199
- require_vi_bdSIJ99Y.globalExpect(postDeleteRead).toBeUndefined();
200
- });
201
- require_vi_bdSIJ99Y.it("should handle large objects efficiently", async () => {
202
- const cache = new require_memory.InMemoryCache();
203
- const largeObject = {
204
- id: 1,
205
- data: Array.from({ length: 1e3 }, (_, i) => ({
206
- index: i,
207
- value: `value-${i}`,
208
- metadata: {
209
- timestamp: Date.now(),
210
- random: Math.random()
211
- }
212
- }))
213
- };
214
- const startTime = Date.now();
215
- await cache.set("large-object", largeObject);
216
- const result = await cache.get("large-object");
217
- const endTime = Date.now();
218
- require_vi_bdSIJ99Y.globalExpect(result).toEqual(largeObject);
219
- require_vi_bdSIJ99Y.globalExpect(endTime - startTime).toBeLessThan(100);
220
- });
221
- });
222
- require_vi_bdSIJ99Y.describe("error scenarios", () => {
223
- require_vi_bdSIJ99Y.it("should handle operations after errors gracefully", async () => {
224
- const cache = new require_memory.InMemoryCache();
225
- await cache.set("valid-key", "valid-value");
226
- require_vi_bdSIJ99Y.globalExpect(await cache.get("valid-key")).toBe("valid-value");
227
- await cache.set("another-key", "another-value");
228
- require_vi_bdSIJ99Y.globalExpect(await cache.get("another-key")).toBe("another-value");
229
- await cache.delete("valid-key");
230
- require_vi_bdSIJ99Y.globalExpect(await cache.get("valid-key")).toBeUndefined();
231
- });
232
- });
233
- });
234
-
235
- //#endregion
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };