@cacheable/node-cache 1.2.0 → 1.3.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 CHANGED
@@ -79,13 +79,21 @@ When initializing the cache you can pass in the options below:
79
79
 
80
80
  ```javascript
81
81
  export type NodeCacheStoreOptions = {
82
- ttl?: number; // The standard ttl as number in seconds for every generated cache element. 0 = unlimited
82
+ ttl?: number; // The standard ttl as number in milliseconds for every generated cache element. 0 = unlimited
83
83
  primary?: Keyv; // The primary storage adapter
84
84
  secondary?: Keyv; // The secondary storage adapter
85
85
  maxKeys?: number; // Default is 0 (unlimited). If this is set it will throw and error if you try to set more keys than the max.
86
86
  };
87
87
  ```
88
88
 
89
+ Note: the `ttl` is now in milliseconds and not seconds like `stdTTL` in `NodeCache`. You can learn more about using shorthand also in the [cacheable documentation](https://github.com/jaredwray/cacheable/blob/main/packages/cacheable/README.md#shorthand-for-time-to-live-ttl). as it is fulling supported. Here is an example:
90
+
91
+ ```javascript
92
+ const cache = new NodeCacheStore({ttl: 60000 }); // 1 minute as it defaults to milliseconds
93
+ cache.set('foo', 'bar', '1h'); // 1 hour
94
+ cache.set('longfoo', 'bar', '1d'); // 1 day
95
+ ```
96
+
89
97
  ### Node Cache Store API
90
98
 
91
99
  * `set(key: string | number, value: any, ttl?: number): Promise<boolean>` - Set a key value pair with an optional ttl (in milliseconds). Will return true on success. If the ttl is not set it will default to 0 (no ttl)
@@ -99,7 +107,7 @@ export type NodeCacheStoreOptions = {
99
107
  * `setTtl(key: string | number, ttl: number): Promise<boolean>` - Set the ttl of a key
100
108
  * `disconnect(): Promise<void>` - Disconnect the storage adapters
101
109
  * `stats`: `NodeCacheStats` - Get the stats of the cache
102
- * `ttl`: `number` - The standard ttl as number in seconds for every generated cache element. 0 = unlimited
110
+ * `ttl`: `number` | `string` - The standard ttl as number in seconds for every generated cache element. `< 0` or `undefined` = unlimited
103
111
  * `primary`: `Keyv` - The primary storage adapter
104
112
  * `secondary`: `Keyv` - The secondary storage adapter
105
113
  * `maxKeys`: `number` - If this is set it will throw and error if you try to set more keys than the max
package/dist/index.cjs CHANGED
@@ -96,8 +96,7 @@ var NodeCacheStore = class {
96
96
  return false;
97
97
  }
98
98
  }
99
- const finalTtl = ttl ?? this._cache.ttl;
100
- await this._cache.set(key.toString(), value, finalTtl);
99
+ await this._cache.set(key.toString(), value, ttl);
101
100
  return true;
102
101
  }
103
102
  async mset(list) {
@@ -127,10 +126,9 @@ var NodeCacheStore = class {
127
126
  return this._cache.clear();
128
127
  }
129
128
  async setTtl(key, ttl) {
130
- const finalTtl = ttl ?? this._cache.ttl;
131
129
  const item = await this._cache.get(key.toString());
132
130
  if (item) {
133
- await this._cache.set(key.toString(), item, finalTtl);
131
+ await this._cache.set(key.toString(), item, ttl);
134
132
  return true;
135
133
  }
136
134
  return false;
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@ import { Cacheable } from 'cacheable';
3
3
  import { Keyv } from 'keyv';
4
4
 
5
5
  type NodeCacheStoreOptions = {
6
- ttl?: number;
6
+ ttl?: number | string;
7
7
  maxKeys?: number;
8
8
  primary?: Keyv;
9
9
  secondary?: Keyv;
@@ -13,8 +13,8 @@ declare class NodeCacheStore {
13
13
  private readonly _cache;
14
14
  constructor(options?: NodeCacheStoreOptions);
15
15
  get cache(): Cacheable;
16
- get ttl(): number | undefined;
17
- set ttl(ttl: number | undefined);
16
+ get ttl(): number | string | undefined;
17
+ set ttl(ttl: number | string | undefined);
18
18
  get primary(): Keyv;
19
19
  set primary(primary: Keyv);
20
20
  get secondary(): Keyv | undefined;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Cacheable } from 'cacheable';
3
3
  import { Keyv } from 'keyv';
4
4
 
5
5
  type NodeCacheStoreOptions = {
6
- ttl?: number;
6
+ ttl?: number | string;
7
7
  maxKeys?: number;
8
8
  primary?: Keyv;
9
9
  secondary?: Keyv;
@@ -13,8 +13,8 @@ declare class NodeCacheStore {
13
13
  private readonly _cache;
14
14
  constructor(options?: NodeCacheStoreOptions);
15
15
  get cache(): Cacheable;
16
- get ttl(): number | undefined;
17
- set ttl(ttl: number | undefined);
16
+ get ttl(): number | string | undefined;
17
+ set ttl(ttl: number | string | undefined);
18
18
  get primary(): Keyv;
19
19
  set primary(primary: Keyv);
20
20
  get secondary(): Keyv | undefined;
package/dist/index.js CHANGED
@@ -60,8 +60,7 @@ var NodeCacheStore = class {
60
60
  return false;
61
61
  }
62
62
  }
63
- const finalTtl = ttl ?? this._cache.ttl;
64
- await this._cache.set(key.toString(), value, finalTtl);
63
+ await this._cache.set(key.toString(), value, ttl);
65
64
  return true;
66
65
  }
67
66
  async mset(list) {
@@ -91,10 +90,9 @@ var NodeCacheStore = class {
91
90
  return this._cache.clear();
92
91
  }
93
92
  async setTtl(key, ttl) {
94
- const finalTtl = ttl ?? this._cache.ttl;
95
93
  const item = await this._cache.get(key.toString());
96
94
  if (item) {
97
- await this._cache.set(key.toString(), item, finalTtl);
95
+ await this._cache.set(key.toString(), item, ttl);
98
96
  return true;
99
97
  }
100
98
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cacheable/node-cache",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Simple and Maintained fast NodeJS internal caching",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -27,7 +27,7 @@
27
27
  "cacheable-node"
28
28
  ],
29
29
  "devDependencies": {
30
- "@types/node": "^22.6.0",
30
+ "@types/node": "^22.7.4",
31
31
  "@vitest/coverage-v8": "^2.1.1",
32
32
  "rimraf": "^6.0.1",
33
33
  "tsup": "^8.3.0",
@@ -36,7 +36,7 @@
36
36
  "xo": "^0.59.3"
37
37
  },
38
38
  "dependencies": {
39
- "cacheable": "^1.3.0",
39
+ "cacheable": "^1.7.0",
40
40
  "eventemitter3": "^5.0.1",
41
41
  "keyv": "^5.0.3"
42
42
  },