@cacheable/node-cache 1.0.0 → 1.2.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
@@ -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<any>` - Get a value from the cache by key
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
@@ -92,7 +92,6 @@ var NodeCacheStore = class {
92
92
  }
93
93
  async set(key, value, ttl) {
94
94
  if (this._maxKeys > 0) {
95
- console.log(this._cache.stats.count, this._maxKeys);
96
95
  if (this._cache.stats.count >= this._maxKeys) {
97
96
  return false;
98
97
  }
@@ -127,6 +126,21 @@ var NodeCacheStore = class {
127
126
  async clear() {
128
127
  return this._cache.clear();
129
128
  }
129
+ async setTtl(key, ttl) {
130
+ const finalTtl = ttl ?? this._cache.ttl;
131
+ const item = await this._cache.get(key.toString());
132
+ if (item) {
133
+ await this._cache.set(key.toString(), item, finalTtl);
134
+ return true;
135
+ }
136
+ return false;
137
+ }
138
+ async take(key) {
139
+ return this._cache.take(key.toString());
140
+ }
141
+ async disconnect() {
142
+ await this._cache.disconnect();
143
+ }
130
144
  };
131
145
 
132
146
  // 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
@@ -56,7 +56,6 @@ var NodeCacheStore = class {
56
56
  }
57
57
  async set(key, value, ttl) {
58
58
  if (this._maxKeys > 0) {
59
- console.log(this._cache.stats.count, this._maxKeys);
60
59
  if (this._cache.stats.count >= this._maxKeys) {
61
60
  return false;
62
61
  }
@@ -91,6 +90,21 @@ var NodeCacheStore = class {
91
90
  async clear() {
92
91
  return this._cache.clear();
93
92
  }
93
+ async setTtl(key, ttl) {
94
+ const finalTtl = ttl ?? this._cache.ttl;
95
+ const item = await this._cache.get(key.toString());
96
+ if (item) {
97
+ await this._cache.set(key.toString(), item, finalTtl);
98
+ return true;
99
+ }
100
+ return false;
101
+ }
102
+ async take(key) {
103
+ return this._cache.take(key.toString());
104
+ }
105
+ async disconnect() {
106
+ await this._cache.disconnect();
107
+ }
94
108
  };
95
109
 
96
110
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cacheable/node-cache",
3
- "version": "1.0.0",
3
+ "version": "1.2.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.5.5",
30
+ "@types/node": "^22.6.0",
31
31
  "@vitest/coverage-v8": "^2.1.1",
32
32
  "rimraf": "^6.0.1",
33
33
  "tsup": "^8.3.0",
@@ -36,9 +36,9 @@
36
36
  "xo": "^0.59.3"
37
37
  },
38
38
  "dependencies": {
39
- "cacheable": "^1.2.0",
39
+ "cacheable": "^1.3.0",
40
40
  "eventemitter3": "^5.0.1",
41
- "keyv": "^5.0.1"
41
+ "keyv": "^5.0.3"
42
42
  },
43
43
  "files": [
44
44
  "dist",