@cacheable/node-cache 1.2.1 → 1.4.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 +9 -3
- package/dist/index.cjs +2 -4
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[<img align="center" src="https://cacheable.org/
|
|
1
|
+
[<img align="center" src="https://cacheable.org/symbol.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable)
|
|
2
2
|
|
|
3
3
|
# Node-Cache
|
|
4
4
|
|
|
@@ -86,7 +86,13 @@ export type NodeCacheStoreOptions = {
|
|
|
86
86
|
};
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
Note: the `ttl` is now in milliseconds and not seconds like `stdTTL` in `NodeCache`.
|
|
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
|
+
```
|
|
90
96
|
|
|
91
97
|
### Node Cache Store API
|
|
92
98
|
|
|
@@ -101,7 +107,7 @@ Note: the `ttl` is now in milliseconds and not seconds like `stdTTL` in `NodeCac
|
|
|
101
107
|
* `setTtl(key: string | number, ttl: number): Promise<boolean>` - Set the ttl of a key
|
|
102
108
|
* `disconnect(): Promise<void>` - Disconnect the storage adapters
|
|
103
109
|
* `stats`: `NodeCacheStats` - Get the stats of the cache
|
|
104
|
-
* `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
|
|
105
111
|
* `primary`: `Keyv` - The primary storage adapter
|
|
106
112
|
* `secondary`: `Keyv` - The secondary storage adapter
|
|
107
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
|
-
|
|
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,
|
|
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;
|
|
@@ -42,7 +42,7 @@ type NodeCacheOptions = {
|
|
|
42
42
|
};
|
|
43
43
|
type NodeCacheItem = {
|
|
44
44
|
key: string | number;
|
|
45
|
-
value:
|
|
45
|
+
value: unknown;
|
|
46
46
|
ttl?: number;
|
|
47
47
|
};
|
|
48
48
|
declare enum NodeCacheErrors {
|
|
@@ -67,8 +67,8 @@ declare class NodeCache extends eventemitter {
|
|
|
67
67
|
constructor(options?: NodeCacheOptions);
|
|
68
68
|
set(key: string | number, value: any, ttl?: number): boolean;
|
|
69
69
|
mset(data: NodeCacheItem[]): boolean;
|
|
70
|
-
get(key: string | number): any;
|
|
71
|
-
mget(keys: Array<string | number>): Record<string, unknown>;
|
|
70
|
+
get<T>(key: string | number): any;
|
|
71
|
+
mget<T>(keys: Array<string | number>): Record<string, unknown>;
|
|
72
72
|
take(key: string | number): any;
|
|
73
73
|
del(key: string | number | Array<string | number>): number;
|
|
74
74
|
mdel(keys: Array<string | number>): number;
|
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;
|
|
@@ -42,7 +42,7 @@ type NodeCacheOptions = {
|
|
|
42
42
|
};
|
|
43
43
|
type NodeCacheItem = {
|
|
44
44
|
key: string | number;
|
|
45
|
-
value:
|
|
45
|
+
value: unknown;
|
|
46
46
|
ttl?: number;
|
|
47
47
|
};
|
|
48
48
|
declare enum NodeCacheErrors {
|
|
@@ -67,8 +67,8 @@ declare class NodeCache extends eventemitter {
|
|
|
67
67
|
constructor(options?: NodeCacheOptions);
|
|
68
68
|
set(key: string | number, value: any, ttl?: number): boolean;
|
|
69
69
|
mset(data: NodeCacheItem[]): boolean;
|
|
70
|
-
get(key: string | number): any;
|
|
71
|
-
mget(keys: Array<string | number>): Record<string, unknown>;
|
|
70
|
+
get<T>(key: string | number): any;
|
|
71
|
+
mget<T>(keys: Array<string | number>): Record<string, unknown>;
|
|
72
72
|
take(key: string | number): any;
|
|
73
73
|
del(key: string | number | Array<string | number>): number;
|
|
74
74
|
mdel(keys: Array<string | number>): number;
|
package/dist/index.js
CHANGED
|
@@ -60,8 +60,7 @@ var NodeCacheStore = class {
|
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
|
|
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,
|
|
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.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Simple and Maintained fast NodeJS internal caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"xo": "^0.59.3"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"cacheable": "^1.
|
|
39
|
+
"cacheable": "^1.7.0",
|
|
40
40
|
"eventemitter3": "^5.0.1",
|
|
41
41
|
"keyv": "^5.0.3"
|
|
42
42
|
},
|