@geekmidas/cache 0.0.1 → 0.0.3
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/__tests__/cache.spec.cjs +1 -1
- package/dist/__tests__/cache.spec.mjs +1 -1
- package/dist/__tests__/upstash.spec.cjs +1 -1
- package/dist/__tests__/upstash.spec.mjs +1 -1
- package/dist/{upstash-s7dedvpn.cjs → upstash-0RolGx7m.cjs} +2 -2
- package/dist/{upstash-Cpe9W0-L.mjs → upstash-_05vyc5o.mjs} +2 -2
- package/dist/upstash.cjs +1 -1
- package/dist/upstash.mjs +1 -1
- package/package.json +15 -5
- package/src/index.ts +22 -0
- package/src/memory.ts +1 -1
- package/src/upstash.ts +3 -3
- package/src/cache.ts +0 -5
- /package/dist/{cache.cjs → index.cjs} +0 -0
- /package/dist/{cache.mjs → index.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_memory = require('../memory-n6Iosq6J.cjs');
|
|
2
|
-
const require_upstash = require('../upstash-
|
|
2
|
+
const require_upstash = require('../upstash-0RolGx7m.cjs');
|
|
3
3
|
const require_vi_DgezovHB = require('../vi.DgezovHB-NqP74KGR.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/__tests__/cache.spec.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, globalExpect, it } from "../vi.DgezovHB-McgltIC5.mjs";
|
|
2
2
|
import { InMemoryCache } from "../memory-YteQXj7m.mjs";
|
|
3
|
-
import { UpstashCache } from "../upstash-
|
|
3
|
+
import { UpstashCache } from "../upstash-_05vyc5o.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/__tests__/cache.spec.ts
|
|
6
6
|
describe("Cache Interface", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.DgezovHB-McgltIC5.mjs";
|
|
2
|
-
import { UpstashCache } from "../upstash-
|
|
2
|
+
import { UpstashCache } from "../upstash-_05vyc5o.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/__tests__/upstash.spec.ts
|
|
5
5
|
describe("UpstashCache", () => {
|
|
@@ -15,8 +15,8 @@ var UpstashCache = class {
|
|
|
15
15
|
if (v === null) return void 0;
|
|
16
16
|
return v;
|
|
17
17
|
}
|
|
18
|
-
async set(key, value) {
|
|
19
|
-
await this.client.set(key, value);
|
|
18
|
+
async set(key, value, ttl = 3600) {
|
|
19
|
+
await this.client.set(key, value, { ex: ttl });
|
|
20
20
|
}
|
|
21
21
|
async delete(key) {
|
|
22
22
|
await this.client.del(key);
|
|
@@ -14,8 +14,8 @@ var UpstashCache = class {
|
|
|
14
14
|
if (v === null) return void 0;
|
|
15
15
|
return v;
|
|
16
16
|
}
|
|
17
|
-
async set(key, value) {
|
|
18
|
-
await this.client.set(key, value);
|
|
17
|
+
async set(key, value, ttl = 3600) {
|
|
18
|
+
await this.client.set(key, value, { ex: ttl });
|
|
19
19
|
}
|
|
20
20
|
async delete(key) {
|
|
21
21
|
await this.client.del(key);
|
package/dist/upstash.cjs
CHANGED
package/dist/upstash.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cache",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Type-safe email client with SMTP support and React templates",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
|
-
"
|
|
9
|
-
"import": "./dist
|
|
10
|
-
"require": "./dist
|
|
11
|
-
"types": "./src
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.cjs",
|
|
11
|
+
"types": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"./memory": {
|
|
14
|
+
"import": "./dist/memory.mjs",
|
|
15
|
+
"require": "./dist/memory.cjs",
|
|
16
|
+
"types": "./src/memory.ts"
|
|
17
|
+
},
|
|
18
|
+
"./upstash": {
|
|
19
|
+
"import": "./dist/upstash.mjs",
|
|
20
|
+
"require": "./dist/upstash.cjs",
|
|
21
|
+
"types": "./src/upstash.ts"
|
|
12
22
|
}
|
|
13
23
|
},
|
|
14
24
|
"publishConfig": {
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Cache<T> {
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a value from the cache.
|
|
4
|
+
*
|
|
5
|
+
* @param key The key to retrieve the value for.
|
|
6
|
+
*/
|
|
7
|
+
get(key: string): Promise<T | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Sets a value in the cache.
|
|
10
|
+
*
|
|
11
|
+
* @param key The key to set the value for.
|
|
12
|
+
* @param value The value to cache.
|
|
13
|
+
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
14
|
+
*/
|
|
15
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Deletes a value from the cache.
|
|
18
|
+
*
|
|
19
|
+
* @param key The key to delete from the cache.
|
|
20
|
+
*/
|
|
21
|
+
delete(key: string): Promise<void>;
|
|
22
|
+
}
|
package/src/memory.ts
CHANGED
package/src/upstash.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Redis } from '@upstash/redis';
|
|
2
|
-
import type { Cache } from './
|
|
2
|
+
import type { Cache } from './';
|
|
3
3
|
|
|
4
4
|
export class UpstashCache<T> implements Cache<T> {
|
|
5
5
|
private client: Redis;
|
|
@@ -21,8 +21,8 @@ export class UpstashCache<T> implements Cache<T> {
|
|
|
21
21
|
return v as T; // Assuming the value is stored as a string, you may need to parse it if it's JSON
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async set(key: string, value: T): Promise<void> {
|
|
25
|
-
await this.client.set(key, value);
|
|
24
|
+
async set(key: string, value: T, ttl = 3600): Promise<void> {
|
|
25
|
+
await this.client.set(key, value, { ex: ttl });
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async delete(key: string): Promise<void> {
|
package/src/cache.ts
DELETED
|
File without changes
|
|
File without changes
|