@geekmidas/cache 0.0.6 → 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.
- package/README.md +68 -3
- 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 +6 -5
- package/dist/expo.d.mts +6 -5
- package/dist/expo.mjs +3 -2
- package/dist/expo.mjs.map +1 -0
- package/dist/{index-B6eF5Yxi.d.cts → index-CExVL1mV.d.cts} +7 -5
- package/dist/{index-Bv61mxVT.d.mts → index-M02PehQA.d.mts} +7 -5
- 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 +6 -5
- package/dist/memory.d.mts +6 -5
- 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 +6 -5
- package/dist/upstash.d.mts +6 -5
- 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 +31 -35
- package/src/__tests__/integration.spec.ts +32 -23
- package/src/__tests__/memory.spec.ts +1 -1
- package/src/__tests__/upstash.spec.ts +1 -1
- package/src/expo.ts +3 -4
- package/src/index.ts +5 -4
- package/src/memory.ts +6 -5
- package/src/upstash.ts +4 -4
- 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
package/README.md
CHANGED
|
@@ -6,11 +6,12 @@ A type-safe, flexible caching library for TypeScript applications with support f
|
|
|
6
6
|
|
|
7
7
|
- **Type-safe**: Full TypeScript support with generics for strongly-typed cache values
|
|
8
8
|
- **Unified interface**: Common `Cache<T>` interface for all implementations
|
|
9
|
-
- **Multiple backends**: In-memory
|
|
9
|
+
- **Multiple backends**: In-memory, Redis (Upstash), and Expo Secure Store implementations
|
|
10
10
|
- **Async API**: Promise-based interface for consistency across implementations
|
|
11
|
-
- **Flexible TTL**: Support for time-to-live
|
|
11
|
+
- **Flexible TTL**: Support for time-to-live across all implementations
|
|
12
12
|
- **Easy testing**: Simple interface makes mocking and testing straightforward
|
|
13
13
|
- **Modular exports**: Import only what you need
|
|
14
|
+
- **React Native support**: Expo Secure Store implementation for mobile apps
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
@@ -25,6 +26,11 @@ For Redis support via Upstash:
|
|
|
25
26
|
npm install @upstash/redis
|
|
26
27
|
```
|
|
27
28
|
|
|
29
|
+
For React Native support via Expo:
|
|
30
|
+
```bash
|
|
31
|
+
npm install expo-secure-store
|
|
32
|
+
```
|
|
33
|
+
|
|
28
34
|
## Quick Start
|
|
29
35
|
|
|
30
36
|
### In-Memory Cache
|
|
@@ -208,6 +214,58 @@ await cache.set('user:1', {
|
|
|
208
214
|
const user = await cache.get('user:1');
|
|
209
215
|
```
|
|
210
216
|
|
|
217
|
+
### ExpoSecureCache
|
|
218
|
+
|
|
219
|
+
Secure storage for React Native apps using Expo SecureStore.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { ExpoSecureCache } from '@geekmidas/cache/expo';
|
|
223
|
+
|
|
224
|
+
class ExpoSecureCache<T> implements Cache<T>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### Features
|
|
228
|
+
|
|
229
|
+
- ✅ Secure, encrypted storage on device
|
|
230
|
+
- ✅ TTL support with automatic expiration
|
|
231
|
+
- ✅ Persistent across app restarts
|
|
232
|
+
- ✅ iOS Keychain & Android Keystore backed
|
|
233
|
+
- ❌ React Native/Expo only
|
|
234
|
+
- ❌ Limited storage capacity (varies by platform)
|
|
235
|
+
- ❌ Slower than in-memory cache
|
|
236
|
+
|
|
237
|
+
#### Example
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
import { ExpoSecureCache } from '@geekmidas/cache/expo';
|
|
241
|
+
|
|
242
|
+
interface AuthTokens {
|
|
243
|
+
accessToken: string;
|
|
244
|
+
refreshToken: string;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const cache = new ExpoSecureCache<AuthTokens>();
|
|
248
|
+
|
|
249
|
+
// Store tokens securely with 1 hour TTL
|
|
250
|
+
await cache.set('auth:tokens', {
|
|
251
|
+
accessToken: 'eyJhbGciOiJIUzI1NiIs...',
|
|
252
|
+
refreshToken: 'dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4...'
|
|
253
|
+
}, 3600);
|
|
254
|
+
|
|
255
|
+
// Retrieve tokens
|
|
256
|
+
const tokens = await cache.get('auth:tokens');
|
|
257
|
+
|
|
258
|
+
// Clear tokens on logout
|
|
259
|
+
await cache.delete('auth:tokens');
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### Platform Considerations
|
|
263
|
+
|
|
264
|
+
- **iOS**: Uses Keychain Services, data persists across app reinstalls
|
|
265
|
+
- **Android**: Uses Android Keystore, data cleared on app uninstall
|
|
266
|
+
- **Storage Limits**: Approximately 2KB per item on most devices
|
|
267
|
+
- **Performance**: Async operations can be slower than memory cache
|
|
268
|
+
|
|
211
269
|
## Advanced Usage
|
|
212
270
|
|
|
213
271
|
### Type Safety
|
|
@@ -289,7 +347,7 @@ Create cache instances based on configuration:
|
|
|
289
347
|
|
|
290
348
|
```typescript
|
|
291
349
|
interface CacheConfig {
|
|
292
|
-
type: 'memory' | 'redis';
|
|
350
|
+
type: 'memory' | 'redis' | 'expo';
|
|
293
351
|
redis?: {
|
|
294
352
|
url: string;
|
|
295
353
|
token: string;
|
|
@@ -303,6 +361,8 @@ function createCache<T>(config: CacheConfig): Cache<T> {
|
|
|
303
361
|
case 'redis':
|
|
304
362
|
if (!config.redis) throw new Error('Redis config required');
|
|
305
363
|
return new UpstashCache<T>(config.redis.url, config.redis.token);
|
|
364
|
+
case 'expo':
|
|
365
|
+
return new ExpoSecureCache<T>();
|
|
306
366
|
default:
|
|
307
367
|
throw new Error(`Unsupported cache type: ${config.type}`);
|
|
308
368
|
}
|
|
@@ -418,6 +478,11 @@ describe('UserService', () => {
|
|
|
418
478
|
- **Cons**: Network latency, external dependency
|
|
419
479
|
- **Best for**: Production, multi-instance apps, shared cache
|
|
420
480
|
|
|
481
|
+
### ExpoSecureCache
|
|
482
|
+
- **Pros**: Secure, encrypted, persistent on device
|
|
483
|
+
- **Cons**: React Native only, storage limits, slower operations
|
|
484
|
+
- **Best for**: Mobile apps, sensitive data (tokens, credentials)
|
|
485
|
+
|
|
421
486
|
### Key Strategies
|
|
422
487
|
|
|
423
488
|
1. **Use appropriate TTL**: Balance between cache freshness and performance
|
|
@@ -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 static getExpiryKey(key: string): string {\n return `${key}:expiresAt`;\n }\n\n async ttl(key: string): Promise<number> {\n const result = await SecureStore.getItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n );\n if (!result) {\n return 0;\n }\n\n const secondsLeft = getExpirationInSeconds(result);\n\n return Math.max(secondsLeft, 0);\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const result = await SecureStore.getItemAsync(key);\n if (!result) {\n return undefined;\n }\n\n const expiresAt = await this.ttl(key);\n if (expiresAt === 0) {\n return undefined;\n }\n\n return JSON.parse(result) as T;\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n const expiresAt = addSeconds(new Date(), ttl).toISOString();\n await SecureStore.setItemAsync(key, JSON.stringify(value));\n await SecureStore.setItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n expiresAt,\n );\n }\n\n async delete(key: string): Promise<void> {\n await SecureStore.deleteItemAsync(key);\n await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n }\n}\n"],"mappings":";;;;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC5C,OAAO,aAAaA,KAAqB;AACvC,UAAQ,EAAE,IAAI;CACf;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,SAAS,MAAM,kBAAY,aAC/B,gBAAgB,aAAa,IAAI,CAClC;AACD,OAAK,OACH,QAAO;EAGT,MAAM,cAAc,mCAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAChC;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,SAAS,MAAM,kBAAY,aAAa,IAAI;AAClD,OAAK,OACH;EAGF,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EAChB;AAGF,SAAO,KAAK,MAAM,OAAO;CAC1B;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACpE,MAAM,YAAY,yCAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,kBAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,kBAAY,aAChB,gBAAgB,aAAa,IAAI,EACjC,UACD;CACF;CAED,MAAM,OAAOF,KAA4B;AACvC,QAAM,kBAAY,gBAAgB,IAAI;AACtC,QAAM,kBAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACrE;AACF"}
|
package/dist/expo.d.cts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-CExVL1mV.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
11
|
//#endregion
|
|
12
|
-
export { ExpoSecureCache };
|
|
12
|
+
export { ExpoSecureCache };
|
|
13
|
+
//# sourceMappingURL=expo.d.cts.map
|
package/dist/expo.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-M02PehQA.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
11
|
//#endregion
|
|
12
|
-
export { ExpoSecureCache };
|
|
12
|
+
export { ExpoSecureCache };
|
|
13
|
+
//# sourceMappingURL=expo.d.mts.map
|
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 static getExpiryKey(key: string): string {\n return `${key}:expiresAt`;\n }\n\n async ttl(key: string): Promise<number> {\n const result = await SecureStore.getItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n );\n if (!result) {\n return 0;\n }\n\n const secondsLeft = getExpirationInSeconds(result);\n\n return Math.max(secondsLeft, 0);\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const result = await SecureStore.getItemAsync(key);\n if (!result) {\n return undefined;\n }\n\n const expiresAt = await this.ttl(key);\n if (expiresAt === 0) {\n return undefined;\n }\n\n return JSON.parse(result) as T;\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n const expiresAt = addSeconds(new Date(), ttl).toISOString();\n await SecureStore.setItemAsync(key, JSON.stringify(value));\n await SecureStore.setItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n expiresAt,\n );\n }\n\n async delete(key: string): Promise<void> {\n await SecureStore.deleteItemAsync(key);\n await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n }\n}\n"],"mappings":";;;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC5C,OAAO,aAAaA,KAAqB;AACvC,UAAQ,EAAE,IAAI;CACf;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,SAAS,MAAM,YAAY,aAC/B,gBAAgB,aAAa,IAAI,CAClC;AACD,OAAK,OACH,QAAO;EAGT,MAAM,cAAc,uBAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAChC;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,SAAS,MAAM,YAAY,aAAa,IAAI;AAClD,OAAK,OACH;EAGF,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EAChB;AAGF,SAAO,KAAK,MAAM,OAAO;CAC1B;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACpE,MAAM,YAAY,2BAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,YAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,YAAY,aAChB,gBAAgB,aAAa,IAAI,EACjC,UACD;CACF;CAED,MAAM,OAAOF,KAA4B;AACvC,QAAM,YAAY,gBAAgB,IAAI;AACtC,QAAM,YAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACrE;AACF"}
|
|
@@ -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,10 @@ 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
|
}
|
|
32
33
|
//#endregion
|
|
33
|
-
export { Cache, getExpirationInSeconds };
|
|
34
|
+
export { Cache, getExpirationInSeconds };
|
|
35
|
+
//# sourceMappingURL=index-CExVL1mV.d.cts.map
|
|
@@ -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,10 @@ 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
|
}
|
|
32
33
|
//#endregion
|
|
33
|
-
export { Cache, getExpirationInSeconds };
|
|
34
|
+
export { Cache, getExpirationInSeconds };
|
|
35
|
+
//# sourceMappingURL=index-M02PehQA.d.mts.map
|
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-CExVL1mV.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-M02PehQA.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 private store: Map<string, unknown> = new Map();\n private expirations: Map<string, Date> = new Map();\n\n async get<T>(key: string): Promise<T | undefined> {\n const expiration = await this.ttl(key);\n if (!expiration) {\n await this.delete(key);\n return undefined;\n }\n\n return this.store.get(key) as T | undefined;\n }\n\n async ttl(key: string): Promise<number> {\n const expiration = this.expirations.get(key);\n if (!expiration) {\n return 0;\n }\n\n return getExpirationInSeconds(expiration);\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n this.store.set(key, value);\n const now = new Date();\n const expiresAt = addSeconds(now, ttl);\n this.expirations.set(key, expiresAt);\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n this.expirations.delete(key);\n }\n}\n"],"mappings":";;;;;AAGA,IAAa,gBAAb,MAA4C;CAC1C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EAChD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AACf,SAAM,KAAK,OAAO,IAAI;AACtB;EACD;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC3B;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACH,QAAO;AAGT,SAAO,mCAAuB,WAAW;CAC1C;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACpE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,yBAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACrC;CAED,MAAM,OAAOF,KAA4B;AACvC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC7B;AACF"}
|
package/dist/memory.d.cts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-CExVL1mV.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
12
|
//#endregion
|
|
13
|
-
export { InMemoryCache };
|
|
13
|
+
export { InMemoryCache };
|
|
14
|
+
//# sourceMappingURL=memory.d.cts.map
|
package/dist/memory.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-M02PehQA.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
12
|
//#endregion
|
|
13
|
-
export { InMemoryCache };
|
|
13
|
+
export { InMemoryCache };
|
|
14
|
+
//# sourceMappingURL=memory.d.mts.map
|
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 private store: Map<string, unknown> = new Map();\n private expirations: Map<string, Date> = new Map();\n\n async get<T>(key: string): Promise<T | undefined> {\n const expiration = await this.ttl(key);\n if (!expiration) {\n await this.delete(key);\n return undefined;\n }\n\n return this.store.get(key) as T | undefined;\n }\n\n async ttl(key: string): Promise<number> {\n const expiration = this.expirations.get(key);\n if (!expiration) {\n return 0;\n }\n\n return getExpirationInSeconds(expiration);\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n this.store.set(key, value);\n const now = new Date();\n const expiresAt = addSeconds(now, ttl);\n this.expirations.set(key, expiresAt);\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n this.expirations.delete(key);\n }\n}\n"],"mappings":";;;;AAGA,IAAa,gBAAb,MAA4C;CAC1C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EAChD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AACf,SAAM,KAAK,OAAO,IAAI;AACtB;EACD;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC3B;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACH,QAAO;AAGT,SAAO,uBAAuB,WAAW;CAC1C;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACpE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,WAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACrC;CAED,MAAM,OAAOF,KAA4B;AACvC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC7B;AACF"}
|
|
@@ -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 expiresAt: string | number | Date | undefined | null,\n): number => {\n if (!expiresAt) {\n return 0;\n }\n\n const expirationDate = new Date(expiresAt);\n const now = new Date();\n\n const secondsLeft = differenceInSeconds(expirationDate, now);\n\n return Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n /**\n * Retrieves a value from the cache.\n *\n * @param key The key to retrieve the value for.\n * @returns The cached value, or undefined if not found.\n */\n get<T>(key: string): Promise<T | undefined>;\n /**\n * Sets a value in the cache.\n *\n * @param key The key to set the value for.\n * @param value The value to cache.\n * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void>;\n /**\n * Deletes a value from the cache.\n *\n * @param key The key to delete from the cache.\n */\n delete(key: string): Promise<void>;\n\n /**\n * Retrieves the time-to-live (TTL) for a cached value.\n *\n * @param key The key to retrieve the TTL for.\n * @returns The TTL in seconds, or 0 if the key does not exist.\n */\n ttl(key: string): Promise<number>;\n}\n"],"mappings":";;;AAEA,MAAa,yBAAyB,CACpCA,cACW;AACX,MAAK,UACH,QAAO;CAGT,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,oBAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAChC"}
|
|
@@ -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 expiresAt: string | number | Date | undefined | null,\n): number => {\n if (!expiresAt) {\n return 0;\n }\n\n const expirationDate = new Date(expiresAt);\n const now = new Date();\n\n const secondsLeft = differenceInSeconds(expirationDate, now);\n\n return Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n /**\n * Retrieves a value from the cache.\n *\n * @param key The key to retrieve the value for.\n * @returns The cached value, or undefined if not found.\n */\n get<T>(key: string): Promise<T | undefined>;\n /**\n * Sets a value in the cache.\n *\n * @param key The key to set the value for.\n * @param value The value to cache.\n * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void>;\n /**\n * Deletes a value from the cache.\n *\n * @param key The key to delete from the cache.\n */\n delete(key: string): Promise<void>;\n\n /**\n * Retrieves the time-to-live (TTL) for a cached value.\n *\n * @param key The key to retrieve the TTL for.\n * @returns The TTL in seconds, or 0 if the key does not exist.\n */\n ttl(key: string): Promise<number>;\n}\n"],"mappings":";;;;AAEA,MAAa,yBAAyB,CACpCA,cACW;AACX,MAAK,UACH,QAAO;CAGT,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,kCAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAChC"}
|
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 private client: Redis;\n\n constructor(url: string, token: string) {\n this.client = new Redis({\n url,\n token,\n });\n }\n\n async ttl(key: string): Promise<number> {\n const ttl = await this.client.ttl(key);\n\n if (ttl === -2) {\n return 0; // Key does not exist\n }\n\n return ttl; // Returns TTL in seconds\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const v = await this.client.get(key);\n\n if (v === null) {\n return undefined;\n }\n\n return v as T;\n }\n\n async set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n await this.client.set(key, value, { ex: ttl });\n }\n\n async delete(key: string): Promise<void> {\n await this.client.del(key);\n }\n}\n"],"mappings":";;;;AAGA,IAAa,eAAb,MAA2C;CACzC,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACtC,OAAK,SAAS,IAAIC,sBAAM;GACtB;GACA;EACD;CACF;CAED,MAAM,IAAIC,KAA8B;EACtC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACV,QAAO;AAGT,SAAO;CACR;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACR;AAGF,SAAO;CACR;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC7D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC/C;CAED,MAAM,OAAOD,KAA4B;AACvC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC3B;AACF"}
|
package/dist/upstash.d.cts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-CExVL1mV.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
12
|
//#endregion
|
|
13
|
-
export { UpstashCache };
|
|
13
|
+
export { UpstashCache };
|
|
14
|
+
//# sourceMappingURL=upstash.d.cts.map
|
package/dist/upstash.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-M02PehQA.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
12
|
//#endregion
|
|
13
|
-
export { UpstashCache };
|
|
13
|
+
export { UpstashCache };
|
|
14
|
+
//# sourceMappingURL=upstash.d.mts.map
|
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 private client: Redis;\n\n constructor(url: string, token: string) {\n this.client = new Redis({\n url,\n token,\n });\n }\n\n async ttl(key: string): Promise<number> {\n const ttl = await this.client.ttl(key);\n\n if (ttl === -2) {\n return 0; // Key does not exist\n }\n\n return ttl; // Returns TTL in seconds\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const v = await this.client.get(key);\n\n if (v === null) {\n return undefined;\n }\n\n return v as T;\n }\n\n async set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n await this.client.set(key, value, { ex: ttl });\n }\n\n async delete(key: string): Promise<void> {\n await this.client.del(key);\n }\n}\n"],"mappings":";;;AAGA,IAAa,eAAb,MAA2C;CACzC,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACtC,OAAK,SAAS,IAAI,MAAM;GACtB;GACA;EACD;CACF;CAED,MAAM,IAAIC,KAA8B;EACtC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACV,QAAO;AAGT,SAAO;CACR;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACR;AAGF,SAAO;CACR;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC7D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC/C;CAED,MAAM,OAAOD,KAA4B;AACvC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC3B;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cache",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.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"
|