@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.
- 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 +8 -5
- package/dist/expo.d.cts.map +1 -0
- package/dist/expo.d.mts +8 -5
- package/dist/expo.d.mts.map +1 -0
- package/dist/expo.mjs +3 -2
- package/dist/expo.mjs.map +1 -0
- package/dist/{index-B6eF5Yxi.d.cts → index-BSYYdwRm.d.cts} +8 -5
- package/dist/index-BSYYdwRm.d.cts.map +1 -0
- package/dist/{index-Bv61mxVT.d.mts → index-Dx96gr-9.d.mts} +8 -5
- package/dist/index-Dx96gr-9.d.mts.map +1 -0
- 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 +8 -5
- package/dist/memory.d.cts.map +1 -0
- package/dist/memory.d.mts +8 -5
- package/dist/memory.d.mts.map +1 -0
- 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 +8 -5
- package/dist/upstash.d.cts.map +1 -0
- package/dist/upstash.d.mts +8 -5
- package/dist/upstash.d.mts.map +1 -0
- 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 +138 -105
- package/src/__tests__/integration.spec.ts +277 -268
- package/src/__tests__/memory.spec.ts +129 -129
- package/src/__tests__/upstash.spec.ts +209 -180
- package/src/expo.ts +45 -46
- package/src/index.ts +37 -36
- package/src/memory.ts +28 -27
- package/src/upstash.ts +28 -28
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +1 -1
- 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
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
8
|
var __copyProps = (to, from, except, desc) => {
|
|
12
9
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
10
|
key = keys[i];
|
|
@@ -25,12 +22,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
22
|
|
|
26
23
|
//#endregion
|
|
27
24
|
|
|
28
|
-
Object.defineProperty(exports, '__commonJS', {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function () {
|
|
31
|
-
return __commonJS;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
25
|
Object.defineProperty(exports, '__toESM', {
|
|
35
26
|
enumerable: true,
|
|
36
27
|
get: function () {
|
package/dist/expo.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
2
|
-
const require_src = require('./src-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_src = require('./src-zfYb7mdS.cjs');
|
|
3
3
|
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
4
4
|
const expo_secure_store = require_chunk.__toESM(require("expo-secure-store"));
|
|
5
5
|
|
|
@@ -33,4 +33,5 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
//#endregion
|
|
36
|
-
exports.ExpoSecureCache = ExpoSecureCache;
|
|
36
|
+
exports.ExpoSecureCache = ExpoSecureCache;
|
|
37
|
+
//# sourceMappingURL=expo.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.cjs","names":["key: string","value: T","ttl: number"],"sources":["../src/expo.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport * as SecureStore from 'expo-secure-store';\nimport { type Cache, getExpirationInSeconds } from './index';\n\nexport class ExpoSecureCache implements Cache {\n\tstatic getExpiryKey(key: string): string {\n\t\treturn `${key}:expiresAt`;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst result = await SecureStore.getItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t);\n\t\tif (!result) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tconst secondsLeft = getExpirationInSeconds(result);\n\n\t\treturn Math.max(secondsLeft, 0);\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst result = await SecureStore.getItemAsync(key);\n\t\tif (!result) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst expiresAt = await this.ttl(key);\n\t\tif (expiresAt === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn JSON.parse(result) as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tconst expiresAt = addSeconds(new Date(), ttl).toISOString();\n\t\tawait SecureStore.setItemAsync(key, JSON.stringify(value));\n\t\tawait SecureStore.setItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t\texpiresAt,\n\t\t);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait SecureStore.deleteItemAsync(key);\n\t\tawait SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n\t}\n}\n"],"mappings":";;;;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC7C,OAAO,aAAaA,KAAqB;AACxC,UAAQ,EAAE,IAAI;CACd;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,SAAS,MAAM,kBAAY,aAChC,gBAAgB,aAAa,IAAI,CACjC;AACD,OAAK,OACJ,QAAO;EAGR,MAAM,cAAc,mCAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAC/B;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,SAAS,MAAM,kBAAY,aAAa,IAAI;AAClD,OAAK,OACJ;EAGD,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EACjB;AAGD,SAAO,KAAK,MAAM,OAAO;CACzB;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACrE,MAAM,YAAY,yCAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,kBAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,kBAAY,aACjB,gBAAgB,aAAa,IAAI,EACjC,UACA;CACD;CAED,MAAM,OAAOF,KAA4B;AACxC,QAAM,kBAAY,gBAAgB,IAAI;AACtC,QAAM,kBAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACpE;AACD"}
|
package/dist/expo.d.cts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-BSYYdwRm.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/expo.d.ts
|
|
4
|
-
declare class ExpoSecureCache
|
|
4
|
+
declare class ExpoSecureCache implements Cache {
|
|
5
5
|
static getExpiryKey(key: string): string;
|
|
6
6
|
ttl(key: string): Promise<number>;
|
|
7
|
-
get(key: string): Promise<T | undefined>;
|
|
8
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
7
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
8
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
9
|
delete(key: string): Promise<void>;
|
|
10
10
|
}
|
|
11
|
+
//# sourceMappingURL=expo.d.ts.map
|
|
12
|
+
|
|
11
13
|
//#endregion
|
|
12
|
-
export { ExpoSecureCache };
|
|
14
|
+
export { ExpoSecureCache };
|
|
15
|
+
//# sourceMappingURL=expo.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.d.cts","names":[],"sources":["../src/expo.ts"],"sourcesContent":[],"mappings":";;;cAIa,eAAA,YAA2B;;EAA3B,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAKY,OALI,CAAA,MAAA,CAAA;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAkBD,OAlBC,CAkBO,CAlBP,GAAA,SAAA,CAAA;EAAA,GAKJ,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EA2BS,CA3BT,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EA2BgC,OA3BhC,CAAA,IAAA,CAAA;EAAO,MAaI,CAAA,GAAA,EAAA,MAAA,CAAA,EAuBR,OAvBQ,CAAA,IAAA,CAAA"}
|
package/dist/expo.d.mts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-Dx96gr-9.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/expo.d.ts
|
|
4
|
-
declare class ExpoSecureCache
|
|
4
|
+
declare class ExpoSecureCache implements Cache {
|
|
5
5
|
static getExpiryKey(key: string): string;
|
|
6
6
|
ttl(key: string): Promise<number>;
|
|
7
|
-
get(key: string): Promise<T | undefined>;
|
|
8
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
7
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
8
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
9
|
delete(key: string): Promise<void>;
|
|
10
10
|
}
|
|
11
|
+
//# sourceMappingURL=expo.d.ts.map
|
|
12
|
+
|
|
11
13
|
//#endregion
|
|
12
|
-
export { ExpoSecureCache };
|
|
14
|
+
export { ExpoSecureCache };
|
|
15
|
+
//# sourceMappingURL=expo.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.d.mts","names":[],"sources":["../src/expo.ts"],"sourcesContent":[],"mappings":";;;cAIa,eAAA,YAA2B;;EAA3B,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAKY,OALI,CAAA,MAAA,CAAA;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAkBD,OAlBC,CAkBO,CAlBP,GAAA,SAAA,CAAA;EAAA,GAKJ,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EA2BS,CA3BT,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EA2BgC,OA3BhC,CAAA,IAAA,CAAA;EAAO,MAaI,CAAA,GAAA,EAAA,MAAA,CAAA,EAuBR,OAvBQ,CAAA,IAAA,CAAA"}
|
package/dist/expo.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getExpirationInSeconds } from "./src-
|
|
1
|
+
import { getExpirationInSeconds } from "./src-CrE4Nl5T.mjs";
|
|
2
2
|
import { addSeconds } from "date-fns";
|
|
3
3
|
import * as SecureStore from "expo-secure-store";
|
|
4
4
|
|
|
@@ -32,4 +32,5 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
//#endregion
|
|
35
|
-
export { ExpoSecureCache };
|
|
35
|
+
export { ExpoSecureCache };
|
|
36
|
+
//# sourceMappingURL=expo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.mjs","names":["key: string","value: T","ttl: number"],"sources":["../src/expo.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport * as SecureStore from 'expo-secure-store';\nimport { type Cache, getExpirationInSeconds } from './index';\n\nexport class ExpoSecureCache implements Cache {\n\tstatic getExpiryKey(key: string): string {\n\t\treturn `${key}:expiresAt`;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst result = await SecureStore.getItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t);\n\t\tif (!result) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tconst secondsLeft = getExpirationInSeconds(result);\n\n\t\treturn Math.max(secondsLeft, 0);\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst result = await SecureStore.getItemAsync(key);\n\t\tif (!result) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst expiresAt = await this.ttl(key);\n\t\tif (expiresAt === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn JSON.parse(result) as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tconst expiresAt = addSeconds(new Date(), ttl).toISOString();\n\t\tawait SecureStore.setItemAsync(key, JSON.stringify(value));\n\t\tawait SecureStore.setItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t\texpiresAt,\n\t\t);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait SecureStore.deleteItemAsync(key);\n\t\tawait SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n\t}\n}\n"],"mappings":";;;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC7C,OAAO,aAAaA,KAAqB;AACxC,UAAQ,EAAE,IAAI;CACd;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,SAAS,MAAM,YAAY,aAChC,gBAAgB,aAAa,IAAI,CACjC;AACD,OAAK,OACJ,QAAO;EAGR,MAAM,cAAc,uBAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAC/B;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,SAAS,MAAM,YAAY,aAAa,IAAI;AAClD,OAAK,OACJ;EAGD,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EACjB;AAGD,SAAO,KAAK,MAAM,OAAO;CACzB;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACrE,MAAM,YAAY,2BAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,YAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,YAAY,aACjB,gBAAgB,aAAa,IAAI,EACjC,UACA;CACD;CAED,MAAM,OAAOF,KAA4B;AACxC,QAAM,YAAY,gBAAgB,IAAI;AACtC,QAAM,YAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACpE;AACD"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
2
|
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
3
|
-
interface Cache
|
|
3
|
+
interface Cache {
|
|
4
4
|
/**
|
|
5
5
|
* Retrieves a value from the cache.
|
|
6
6
|
*
|
|
7
7
|
* @param key The key to retrieve the value for.
|
|
8
|
+
* @returns The cached value, or undefined if not found.
|
|
8
9
|
*/
|
|
9
|
-
get(key: string): Promise<T | undefined>;
|
|
10
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
10
11
|
/**
|
|
11
12
|
* Sets a value in the cache.
|
|
12
13
|
*
|
|
@@ -14,7 +15,7 @@ interface Cache<T> {
|
|
|
14
15
|
* @param value The value to cache.
|
|
15
16
|
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
16
17
|
*/
|
|
17
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
18
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
18
19
|
/**
|
|
19
20
|
* Deletes a value from the cache.
|
|
20
21
|
*
|
|
@@ -25,9 +26,11 @@ interface Cache<T> {
|
|
|
25
26
|
* Retrieves the time-to-live (TTL) for a cached value.
|
|
26
27
|
*
|
|
27
28
|
* @param key The key to retrieve the TTL for.
|
|
28
|
-
* @returns The TTL in seconds, or
|
|
29
|
+
* @returns The TTL in seconds, or 0 if the key does not exist.
|
|
29
30
|
*/
|
|
30
31
|
ttl(key: string): Promise<number>;
|
|
31
32
|
}
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
32
34
|
//#endregion
|
|
33
|
-
export { Cache, getExpirationInSeconds };
|
|
35
|
+
export { Cache, getExpirationInSeconds };
|
|
36
|
+
//# sourceMappingURL=index-BSYYdwRm.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BSYYdwRm.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";cAEa,sDACiB;AADjB,UAeI,KAAA,CAfJ;EAeI;;;;;;EAeoC,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAdA,OAcA,CAdQ,CAcR,GAAA,SAAA,CAAA;EAAO;AAQH;;;;;;6BAdE,kBAAkB;;;;;;uBAMxB;;;;;;;oBAQH"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
2
|
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
3
|
-
interface Cache
|
|
3
|
+
interface Cache {
|
|
4
4
|
/**
|
|
5
5
|
* Retrieves a value from the cache.
|
|
6
6
|
*
|
|
7
7
|
* @param key The key to retrieve the value for.
|
|
8
|
+
* @returns The cached value, or undefined if not found.
|
|
8
9
|
*/
|
|
9
|
-
get(key: string): Promise<T | undefined>;
|
|
10
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
10
11
|
/**
|
|
11
12
|
* Sets a value in the cache.
|
|
12
13
|
*
|
|
@@ -14,7 +15,7 @@ interface Cache<T> {
|
|
|
14
15
|
* @param value The value to cache.
|
|
15
16
|
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
16
17
|
*/
|
|
17
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
18
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
18
19
|
/**
|
|
19
20
|
* Deletes a value from the cache.
|
|
20
21
|
*
|
|
@@ -25,9 +26,11 @@ interface Cache<T> {
|
|
|
25
26
|
* Retrieves the time-to-live (TTL) for a cached value.
|
|
26
27
|
*
|
|
27
28
|
* @param key The key to retrieve the TTL for.
|
|
28
|
-
* @returns The TTL in seconds, or
|
|
29
|
+
* @returns The TTL in seconds, or 0 if the key does not exist.
|
|
29
30
|
*/
|
|
30
31
|
ttl(key: string): Promise<number>;
|
|
31
32
|
}
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
32
34
|
//#endregion
|
|
33
|
-
export { Cache, getExpirationInSeconds };
|
|
35
|
+
export { Cache, getExpirationInSeconds };
|
|
36
|
+
//# sourceMappingURL=index-Dx96gr-9.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Dx96gr-9.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";cAEa,sDACiB;AADjB,UAeI,KAAA,CAfJ;EAeI;;;;;;EAeoC,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAdA,OAcA,CAdQ,CAcR,GAAA,SAAA,CAAA;EAAO;AAQH;;;;;;6BAdE,kBAAkB;;;;;;uBAMxB;;;;;;;oBAQH"}
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Cache, getExpirationInSeconds } from "./index-
|
|
1
|
+
import { Cache, getExpirationInSeconds } from "./index-BSYYdwRm.cjs";
|
|
2
2
|
export { Cache, getExpirationInSeconds };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Cache, getExpirationInSeconds } from "./index-
|
|
1
|
+
import { Cache, getExpirationInSeconds } from "./index-Dx96gr-9.mjs";
|
|
2
2
|
export { Cache, getExpirationInSeconds };
|
package/dist/index.mjs
CHANGED
package/dist/memory.cjs
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
require('./
|
|
2
|
-
const
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_src = require('./src-zfYb7mdS.cjs');
|
|
3
|
+
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
3
4
|
|
|
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
|
+
this.expirations.delete(key);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.InMemoryCache = InMemoryCache;
|
|
36
|
+
//# sourceMappingURL=memory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.cjs","names":["key: string","value: T","ttl: number"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n\tprivate store: Map<string, unknown> = new Map();\n\tprivate expirations: Map<string, Date> = new Map();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst expiration = await this.ttl(key);\n\t\tif (!expiration) {\n\t\t\tawait this.delete(key);\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst expiration = this.expirations.get(key);\n\t\tif (!expiration) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn getExpirationInSeconds(expiration);\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tthis.store.set(key, value);\n\t\tconst now = new Date();\n\t\tconst expiresAt = addSeconds(now, ttl);\n\t\tthis.expirations.set(key, expiresAt);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t\tthis.expirations.delete(key);\n\t}\n}\n"],"mappings":";;;;;AAGA,IAAa,gBAAb,MAA4C;CAC3C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EACjD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AAChB,SAAM,KAAK,OAAO,IAAI;AACtB;EACA;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC1B;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACJ,QAAO;AAGR,SAAO,mCAAuB,WAAW;CACzC;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACrE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,yBAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACpC;CAED,MAAM,OAAOF,KAA4B;AACxC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC5B;AACD"}
|
package/dist/memory.d.cts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-BSYYdwRm.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/memory.d.ts
|
|
4
|
-
declare class InMemoryCache
|
|
4
|
+
declare class InMemoryCache implements Cache {
|
|
5
5
|
private store;
|
|
6
6
|
private expirations;
|
|
7
|
-
get(key: string): Promise<T | undefined>;
|
|
7
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
8
8
|
ttl(key: string): Promise<number>;
|
|
9
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
11
|
}
|
|
12
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
13
|
+
|
|
12
14
|
//#endregion
|
|
13
|
-
export { InMemoryCache };
|
|
15
|
+
export { InMemoryCache };
|
|
16
|
+
//# sourceMappingURL=memory.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.cts","names":[],"sources":["../src/memory.ts"],"sourcesContent":[],"mappings":";;;cAGa,aAAA,YAAyB;;EAAzB,QAAA,WAAc;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAIC,OAJD,CAIS,CAJT,GAAA,SAAA,CAAA;EAAA,GAIS,CAAA,GAAA,EAAA,MAAA,CAAA,EAUX,OAVW,CAAA,MAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAmBM,CAnBN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmB6B,OAnB7B,CAAA,IAAA,CAAA;EAAO,MAUV,CAAA,GAAA,EAAA,MAAA,CAAA,EAgBG,OAhBH,CAAA,IAAA,CAAA"}
|
package/dist/memory.d.mts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-Dx96gr-9.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/memory.d.ts
|
|
4
|
-
declare class InMemoryCache
|
|
4
|
+
declare class InMemoryCache implements Cache {
|
|
5
5
|
private store;
|
|
6
6
|
private expirations;
|
|
7
|
-
get(key: string): Promise<T | undefined>;
|
|
7
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
8
8
|
ttl(key: string): Promise<number>;
|
|
9
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
11
|
}
|
|
12
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
13
|
+
|
|
12
14
|
//#endregion
|
|
13
|
-
export { InMemoryCache };
|
|
15
|
+
export { InMemoryCache };
|
|
16
|
+
//# sourceMappingURL=memory.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.mts","names":[],"sources":["../src/memory.ts"],"sourcesContent":[],"mappings":";;;cAGa,aAAA,YAAyB;;EAAzB,QAAA,WAAc;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAIC,OAJD,CAIS,CAJT,GAAA,SAAA,CAAA;EAAA,GAIS,CAAA,GAAA,EAAA,MAAA,CAAA,EAUX,OAVW,CAAA,MAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAmBM,CAnBN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmB6B,OAnB7B,CAAA,IAAA,CAAA;EAAO,MAUV,CAAA,GAAA,EAAA,MAAA,CAAA,EAgBG,OAhBH,CAAA,IAAA,CAAA"}
|
package/dist/memory.mjs
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
|
-
import "./src-
|
|
2
|
-
import {
|
|
1
|
+
import { getExpirationInSeconds } from "./src-CrE4Nl5T.mjs";
|
|
2
|
+
import { addSeconds } from "date-fns";
|
|
3
3
|
|
|
4
|
-
|
|
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
|
+
this.expirations.delete(key);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { InMemoryCache };
|
|
35
|
+
//# sourceMappingURL=memory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.mjs","names":["key: string","value: T","ttl: number"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n\tprivate store: Map<string, unknown> = new Map();\n\tprivate expirations: Map<string, Date> = new Map();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst expiration = await this.ttl(key);\n\t\tif (!expiration) {\n\t\t\tawait this.delete(key);\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst expiration = this.expirations.get(key);\n\t\tif (!expiration) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn getExpirationInSeconds(expiration);\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tthis.store.set(key, value);\n\t\tconst now = new Date();\n\t\tconst expiresAt = addSeconds(now, ttl);\n\t\tthis.expirations.set(key, expiresAt);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t\tthis.expirations.delete(key);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,gBAAb,MAA4C;CAC3C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EACjD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AAChB,SAAM,KAAK,OAAO,IAAI;AACtB;EACA;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC1B;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACJ,QAAO;AAGR,SAAO,uBAAuB,WAAW;CACzC;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACrE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,WAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACpC;CAED,MAAM,OAAOF,KAA4B;AACxC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC5B;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-CrE4Nl5T.mjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n"],"mappings":";;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,oBAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
2
|
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
3
3
|
|
|
4
4
|
//#region src/index.ts
|
|
@@ -16,4 +16,5 @@ Object.defineProperty(exports, 'getExpirationInSeconds', {
|
|
|
16
16
|
get: function () {
|
|
17
17
|
return getExpirationInSeconds;
|
|
18
18
|
}
|
|
19
|
-
});
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=src-zfYb7mdS.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-zfYb7mdS.cjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n"],"mappings":";;;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,kCAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
|
package/dist/upstash.cjs
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const __upstash_redis = require_chunk.__toESM(require("@upstash/redis"));
|
|
2
3
|
|
|
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
|
+
exports.UpstashCache = UpstashCache;
|
|
33
|
+
//# sourceMappingURL=upstash.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstash.cjs","names":["url: string","token: string","Redis","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,eAAb,MAA2C;CAC1C,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAIC,sBAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD"}
|
package/dist/upstash.d.cts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-BSYYdwRm.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/upstash.d.ts
|
|
4
|
-
declare class UpstashCache
|
|
4
|
+
declare class UpstashCache implements Cache {
|
|
5
5
|
private client;
|
|
6
6
|
constructor(url: string, token: string);
|
|
7
7
|
ttl(key: string): Promise<number>;
|
|
8
|
-
get(key: string): Promise<T | undefined>;
|
|
9
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
8
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
9
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
11
|
}
|
|
12
|
+
//# sourceMappingURL=upstash.d.ts.map
|
|
13
|
+
|
|
12
14
|
//#endregion
|
|
13
|
-
export { UpstashCache };
|
|
15
|
+
export { UpstashCache };
|
|
16
|
+
//# sourceMappingURL=upstash.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstash.d.cts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAGa,YAAA,YAAwB;;EAAxB,WAAA,CAAA,GAAa,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUD,OAVC,CAAA,MAAA,CAAA;EAAA,GAUD,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUG,OAVH,CAUW,CAVX,GAAA,SAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUF,CAVE,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUc,OAVd,CAAA,IAAA,CAAA;EAAC,MAAT,CAAA,GAAA,EAAA,MAAA,CAAA,EAcA,OAdA,CAAA,IAAA,CAAA"}
|
package/dist/upstash.d.mts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-Dx96gr-9.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/upstash.d.ts
|
|
4
|
-
declare class UpstashCache
|
|
4
|
+
declare class UpstashCache implements Cache {
|
|
5
5
|
private client;
|
|
6
6
|
constructor(url: string, token: string);
|
|
7
7
|
ttl(key: string): Promise<number>;
|
|
8
|
-
get(key: string): Promise<T | undefined>;
|
|
9
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
8
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
9
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
11
|
}
|
|
12
|
+
//# sourceMappingURL=upstash.d.ts.map
|
|
13
|
+
|
|
12
14
|
//#endregion
|
|
13
|
-
export { UpstashCache };
|
|
15
|
+
export { UpstashCache };
|
|
16
|
+
//# sourceMappingURL=upstash.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstash.d.mts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAGa,YAAA,YAAwB;;EAAxB,WAAA,CAAA,GAAa,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUD,OAVC,CAAA,MAAA,CAAA;EAAA,GAUD,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUG,OAVH,CAUW,CAVX,GAAA,SAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUF,CAVE,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUc,OAVd,CAAA,IAAA,CAAA;EAAC,MAAT,CAAA,GAAA,EAAA,MAAA,CAAA,EAcA,OAdA,CAAA,IAAA,CAAA"}
|
package/dist/upstash.mjs
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Redis } from "@upstash/redis";
|
|
2
2
|
|
|
3
|
-
|
|
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 };
|
|
32
|
+
//# sourceMappingURL=upstash.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstash.mjs","names":["url: string","token: string","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n"],"mappings":";;;AAGA,IAAa,eAAb,MAA2C;CAC1C,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAI,MAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cache",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Unified cache interface with multiple storage implementations",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"require": "./dist/expo.cjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/geekmidas/toolbox"
|
|
32
|
+
},
|
|
29
33
|
"publishConfig": {
|
|
30
34
|
"registry": "https://registry.npmjs.org/",
|
|
31
35
|
"access": "public"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { bench, describe } from 'vitest';
|
|
2
|
+
import { InMemoryCache } from '../memory';
|
|
3
|
+
|
|
4
|
+
describe('InMemoryCache', () => {
|
|
5
|
+
const cache = new InMemoryCache();
|
|
6
|
+
|
|
7
|
+
bench('set with TTL', async () => {
|
|
8
|
+
await cache.set('key', 'value', 3600);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
bench('get (cache hit)', async () => {
|
|
12
|
+
await cache.set('hit-key', 'value', 3600);
|
|
13
|
+
await cache.get('hit-key');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
bench('get (cache miss)', async () => {
|
|
17
|
+
await cache.get('nonexistent-key');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
bench('delete', async () => {
|
|
21
|
+
await cache.set('delete-key', 'value', 3600);
|
|
22
|
+
await cache.delete('delete-key');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
bench('set + get cycle', async () => {
|
|
26
|
+
const key = `cycle-${Math.random()}`;
|
|
27
|
+
await cache.set(key, 'value', 3600);
|
|
28
|
+
await cache.get(key);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('InMemoryCache - Large Scale', () => {
|
|
33
|
+
bench('1000 sequential sets', async () => {
|
|
34
|
+
const cache = new InMemoryCache();
|
|
35
|
+
for (let i = 0; i < 1000; i++) {
|
|
36
|
+
await cache.set(`key-${i}`, `value-${i}`, 3600);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
bench('1000 sequential gets', async () => {
|
|
41
|
+
const cache = new InMemoryCache();
|
|
42
|
+
// Pre-populate
|
|
43
|
+
for (let i = 0; i < 1000; i++) {
|
|
44
|
+
await cache.set(`key-${i}`, `value-${i}`, 3600);
|
|
45
|
+
}
|
|
46
|
+
// Benchmark gets
|
|
47
|
+
for (let i = 0; i < 1000; i++) {
|
|
48
|
+
await cache.get(`key-${i}`);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|