@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.
Files changed (63) 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 +6 -5
  5. package/dist/expo.d.mts +6 -5
  6. package/dist/expo.mjs +3 -2
  7. package/dist/expo.mjs.map +1 -0
  8. package/dist/{index-B6eF5Yxi.d.cts → index-CExVL1mV.d.cts} +7 -5
  9. package/dist/{index-Bv61mxVT.d.mts → index-M02PehQA.d.mts} +7 -5
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +1 -1
  14. package/dist/memory.cjs +35 -3
  15. package/dist/memory.cjs.map +1 -0
  16. package/dist/memory.d.cts +6 -5
  17. package/dist/memory.d.mts +6 -5
  18. package/dist/memory.mjs +34 -3
  19. package/dist/memory.mjs.map +1 -0
  20. package/dist/{src-DVpoP03o.mjs → src-CrE4Nl5T.mjs} +2 -1
  21. package/dist/src-CrE4Nl5T.mjs.map +1 -0
  22. package/dist/{src-C7d6HaTp.cjs → src-zfYb7mdS.cjs} +3 -2
  23. package/dist/src-zfYb7mdS.cjs.map +1 -0
  24. package/dist/upstash.cjs +32 -2
  25. package/dist/upstash.cjs.map +1 -0
  26. package/dist/upstash.d.cts +6 -5
  27. package/dist/upstash.d.mts +6 -5
  28. package/dist/upstash.mjs +31 -2
  29. package/dist/upstash.mjs.map +1 -0
  30. package/package.json +6 -2
  31. package/src/__benchmarks__/memory.bench.ts +51 -0
  32. package/src/__tests__/cache.spec.ts +31 -35
  33. package/src/__tests__/integration.spec.ts +32 -23
  34. package/src/__tests__/memory.spec.ts +1 -1
  35. package/src/__tests__/upstash.spec.ts +1 -1
  36. package/src/expo.ts +3 -4
  37. package/src/index.ts +5 -4
  38. package/src/memory.ts +6 -5
  39. package/src/upstash.ts +4 -4
  40. package/dist/__tests__/cache.spec.cjs +0 -77
  41. package/dist/__tests__/cache.spec.d.cts +0 -1
  42. package/dist/__tests__/cache.spec.d.mts +0 -1
  43. package/dist/__tests__/cache.spec.mjs +0 -77
  44. package/dist/__tests__/integration.spec.cjs +0 -235
  45. package/dist/__tests__/integration.spec.d.cts +0 -1
  46. package/dist/__tests__/integration.spec.d.mts +0 -1
  47. package/dist/__tests__/integration.spec.mjs +0 -235
  48. package/dist/__tests__/memory.spec.cjs +0 -126
  49. package/dist/__tests__/memory.spec.d.cts +0 -1
  50. package/dist/__tests__/memory.spec.d.mts +0 -1
  51. package/dist/__tests__/memory.spec.mjs +0 -126
  52. package/dist/__tests__/upstash.spec.cjs +0 -201
  53. package/dist/__tests__/upstash.spec.d.cts +0 -1
  54. package/dist/__tests__/upstash.spec.d.mts +0 -1
  55. package/dist/__tests__/upstash.spec.mjs +0 -201
  56. package/dist/magic-string.es-CBih0MJw.mjs +0 -1014
  57. package/dist/magic-string.es-KiPEzMtt.cjs +0 -1015
  58. package/dist/memory-Csy6J-Ak.cjs +0 -39
  59. package/dist/memory-QDTnSEX5.mjs +0 -33
  60. package/dist/upstash-CXy_duOa.mjs +0 -31
  61. package/dist/upstash-u8Hs4sZG.cjs +0 -37
  62. package/dist/vi.bdSIJ99Y-B-qkABPq.cjs +0 -14955
  63. 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
- });