@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
@@ -1,39 +0,0 @@
1
- const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const require_src = require('./src-C7d6HaTp.cjs');
3
- const date_fns = require_chunk.__toESM(require("date-fns"));
4
-
5
- //#region src/memory.ts
6
- var InMemoryCache = class {
7
- store = /* @__PURE__ */ new Map();
8
- expirations = /* @__PURE__ */ new Map();
9
- async get(key) {
10
- const expiration = await this.ttl(key);
11
- if (!expiration) {
12
- await this.delete(key);
13
- return void 0;
14
- }
15
- return this.store.get(key);
16
- }
17
- async ttl(key) {
18
- const expiration = this.expirations.get(key);
19
- if (!expiration) return 0;
20
- return require_src.getExpirationInSeconds(expiration);
21
- }
22
- async set(key, value, ttl = 600) {
23
- this.store.set(key, value);
24
- const now = /* @__PURE__ */ new Date();
25
- const expiresAt = (0, date_fns.addSeconds)(now, ttl);
26
- this.expirations.set(key, expiresAt);
27
- }
28
- async delete(key) {
29
- this.store.delete(key);
30
- }
31
- };
32
-
33
- //#endregion
34
- Object.defineProperty(exports, 'InMemoryCache', {
35
- enumerable: true,
36
- get: function () {
37
- return InMemoryCache;
38
- }
39
- });
@@ -1,33 +0,0 @@
1
- import { getExpirationInSeconds } from "./src-DVpoP03o.mjs";
2
- import { addSeconds } from "date-fns";
3
-
4
- //#region src/memory.ts
5
- var InMemoryCache = class {
6
- store = /* @__PURE__ */ new Map();
7
- expirations = /* @__PURE__ */ new Map();
8
- async get(key) {
9
- const expiration = await this.ttl(key);
10
- if (!expiration) {
11
- await this.delete(key);
12
- return void 0;
13
- }
14
- return this.store.get(key);
15
- }
16
- async ttl(key) {
17
- const expiration = this.expirations.get(key);
18
- if (!expiration) return 0;
19
- return getExpirationInSeconds(expiration);
20
- }
21
- async set(key, value, ttl = 600) {
22
- this.store.set(key, value);
23
- const now = /* @__PURE__ */ new Date();
24
- const expiresAt = addSeconds(now, ttl);
25
- this.expirations.set(key, expiresAt);
26
- }
27
- async delete(key) {
28
- this.store.delete(key);
29
- }
30
- };
31
-
32
- //#endregion
33
- export { InMemoryCache };
@@ -1,31 +0,0 @@
1
- import { Redis } from "@upstash/redis";
2
-
3
- //#region src/upstash.ts
4
- var UpstashCache = class {
5
- client;
6
- constructor(url, token) {
7
- this.client = new Redis({
8
- url,
9
- token
10
- });
11
- }
12
- async ttl(key) {
13
- const ttl = await this.client.ttl(key);
14
- if (ttl === -2) return 0;
15
- return ttl;
16
- }
17
- async get(key) {
18
- const v = await this.client.get(key);
19
- if (v === null) return void 0;
20
- return v;
21
- }
22
- async set(key, value, ttl = 3600) {
23
- await this.client.set(key, value, { ex: ttl });
24
- }
25
- async delete(key) {
26
- await this.client.del(key);
27
- }
28
- };
29
-
30
- //#endregion
31
- export { UpstashCache };
@@ -1,37 +0,0 @@
1
- const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const __upstash_redis = require_chunk.__toESM(require("@upstash/redis"));
3
-
4
- //#region src/upstash.ts
5
- var UpstashCache = class {
6
- client;
7
- constructor(url, token) {
8
- this.client = new __upstash_redis.Redis({
9
- url,
10
- token
11
- });
12
- }
13
- async ttl(key) {
14
- const ttl = await this.client.ttl(key);
15
- if (ttl === -2) return 0;
16
- return ttl;
17
- }
18
- async get(key) {
19
- const v = await this.client.get(key);
20
- if (v === null) return void 0;
21
- return v;
22
- }
23
- async set(key, value, ttl = 3600) {
24
- await this.client.set(key, value, { ex: ttl });
25
- }
26
- async delete(key) {
27
- await this.client.del(key);
28
- }
29
- };
30
-
31
- //#endregion
32
- Object.defineProperty(exports, 'UpstashCache', {
33
- enumerable: true,
34
- get: function () {
35
- return UpstashCache;
36
- }
37
- });