@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.
@@ -1,5 +1,5 @@
1
1
  const require_memory = require('../memory-n6Iosq6J.cjs');
2
- const require_upstash = require('../upstash-s7dedvpn.cjs');
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-Cpe9W0-L.mjs";
3
+ import { UpstashCache } from "../upstash-_05vyc5o.mjs";
4
4
 
5
5
  //#region src/__tests__/cache.spec.ts
6
6
  describe("Cache Interface", () => {
@@ -1,4 +1,4 @@
1
- const require_upstash = require('../upstash-s7dedvpn.cjs');
1
+ const require_upstash = require('../upstash-0RolGx7m.cjs');
2
2
  const require_vi_DgezovHB = require('../vi.DgezovHB-NqP74KGR.cjs');
3
3
 
4
4
  //#region src/__tests__/upstash.spec.ts
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.DgezovHB-McgltIC5.mjs";
2
- import { UpstashCache } from "../upstash-Cpe9W0-L.mjs";
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
@@ -1,3 +1,3 @@
1
- const require_upstash = require('./upstash-s7dedvpn.cjs');
1
+ const require_upstash = require('./upstash-0RolGx7m.cjs');
2
2
 
3
3
  exports.UpstashCache = require_upstash.UpstashCache;
package/dist/upstash.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { UpstashCache } from "./upstash-Cpe9W0-L.mjs";
1
+ import { UpstashCache } from "./upstash-_05vyc5o.mjs";
2
2
 
3
3
  export { UpstashCache };
package/package.json CHANGED
@@ -1,14 +1,24 @@
1
1
  {
2
2
  "name": "@geekmidas/cache",
3
- "version": "0.0.1",
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/*.mjs",
10
- "require": "./dist/*.cjs",
11
- "types": "./src/*.ts"
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
@@ -1,4 +1,4 @@
1
- import type { Cache } from './cache';
1
+ import type { Cache } from './';
2
2
 
3
3
  export class InMemoryCache<T> implements Cache<T> {
4
4
  private store: Map<string, T> = new Map();
package/src/upstash.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Redis } from '@upstash/redis';
2
- import type { Cache } from './cache';
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
@@ -1,5 +0,0 @@
1
- export interface Cache<T> {
2
- get(key: string): Promise<T | undefined>;
3
- set(key: string, value: T): Promise<void>;
4
- delete(key: string): Promise<void>;
5
- }
File without changes
File without changes