@cacheable/node-cache 1.0.0 → 1.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 +4 -1
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,11 +90,14 @@ export type NodeCacheStoreOptions = {
|
|
|
90
90
|
|
|
91
91
|
* `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)
|
|
92
92
|
* `mset(data: Array<NodeCacheItem>): Promise<boolean>` - Set multiple key value pairs at once
|
|
93
|
-
* `get(key: string | number): Promise<
|
|
93
|
+
* `get<T>(key: string | number): Promise<T>` - Get a value from the cache by key
|
|
94
94
|
* `mget(keys: Array<string | number>): Promise<Record<string, unknown>>` - Get multiple values from the cache by keys
|
|
95
|
+
* `take<T>(key: string | number): Promise<T>` - Get a value from the cache by key and delete it
|
|
95
96
|
* `del(key: string | number): Promise<boolean>` - Delete a key
|
|
96
97
|
* `mdel(keys: Array<string | number>): Promise<boolean>` - Delete multiple keys
|
|
97
98
|
* `clear(): Promise<void>` - Clear the cache
|
|
99
|
+
* `setTtl(key: string | number, ttl: number): Promise<boolean>` - Set the ttl of a key
|
|
100
|
+
* `disconnect(): Promise<void>` - Disconnect the storage adapters
|
|
98
101
|
* `stats`: `NodeCacheStats` - Get the stats of the cache
|
|
99
102
|
* `ttl`: `number` - The standard ttl as number in seconds for every generated cache element. 0 = unlimited
|
|
100
103
|
* `primary`: `Keyv` - The primary storage adapter
|
package/dist/index.cjs
CHANGED
|
@@ -127,6 +127,21 @@ var NodeCacheStore = class {
|
|
|
127
127
|
async clear() {
|
|
128
128
|
return this._cache.clear();
|
|
129
129
|
}
|
|
130
|
+
async setTtl(key, ttl) {
|
|
131
|
+
const finalTtl = ttl ?? this._cache.ttl;
|
|
132
|
+
const item = await this._cache.get(key.toString());
|
|
133
|
+
if (item) {
|
|
134
|
+
await this._cache.set(key.toString(), item, finalTtl);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
async take(key) {
|
|
140
|
+
return this._cache.take(key.toString());
|
|
141
|
+
}
|
|
142
|
+
async disconnect() {
|
|
143
|
+
await this._cache.disconnect();
|
|
144
|
+
}
|
|
130
145
|
};
|
|
131
146
|
|
|
132
147
|
// src/index.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -28,6 +28,9 @@ declare class NodeCacheStore {
|
|
|
28
28
|
del(key: string | number): Promise<boolean>;
|
|
29
29
|
mdel(keys: Array<string | number>): Promise<boolean>;
|
|
30
30
|
clear(): Promise<void>;
|
|
31
|
+
setTtl(key: string | number, ttl?: number): Promise<boolean>;
|
|
32
|
+
take<T>(key: string | number): Promise<T | undefined>;
|
|
33
|
+
disconnect(): Promise<void>;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
type NodeCacheOptions = {
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,9 @@ declare class NodeCacheStore {
|
|
|
28
28
|
del(key: string | number): Promise<boolean>;
|
|
29
29
|
mdel(keys: Array<string | number>): Promise<boolean>;
|
|
30
30
|
clear(): Promise<void>;
|
|
31
|
+
setTtl(key: string | number, ttl?: number): Promise<boolean>;
|
|
32
|
+
take<T>(key: string | number): Promise<T | undefined>;
|
|
33
|
+
disconnect(): Promise<void>;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
type NodeCacheOptions = {
|
package/dist/index.js
CHANGED
|
@@ -91,6 +91,21 @@ var NodeCacheStore = class {
|
|
|
91
91
|
async clear() {
|
|
92
92
|
return this._cache.clear();
|
|
93
93
|
}
|
|
94
|
+
async setTtl(key, ttl) {
|
|
95
|
+
const finalTtl = ttl ?? this._cache.ttl;
|
|
96
|
+
const item = await this._cache.get(key.toString());
|
|
97
|
+
if (item) {
|
|
98
|
+
await this._cache.set(key.toString(), item, finalTtl);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
async take(key) {
|
|
104
|
+
return this._cache.take(key.toString());
|
|
105
|
+
}
|
|
106
|
+
async disconnect() {
|
|
107
|
+
await this._cache.disconnect();
|
|
108
|
+
}
|
|
94
109
|
};
|
|
95
110
|
|
|
96
111
|
// src/index.ts
|