@cacheable/node-cache 1.5.0 → 1.5.1
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 +12 -1
- package/dist/index.cjs +14 -18
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +13 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ npm install @cacheable/node-cache --save
|
|
|
37
37
|
# Basic Usage
|
|
38
38
|
|
|
39
39
|
```javascript
|
|
40
|
-
import
|
|
40
|
+
import NodeCache from '@cacheable/node-cache';
|
|
41
41
|
|
|
42
42
|
const cache = new NodeCache();
|
|
43
43
|
cache.set('foo', 'bar');
|
|
@@ -50,6 +50,16 @@ cache.del('foo'); // true
|
|
|
50
50
|
cache.set('bar', 'baz', '35m'); // 35 minutes using shorthand
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
# NodeCache Not Default Export
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
import {NodeCache} from '@cacheable/node-cache';
|
|
57
|
+
|
|
58
|
+
const cache = new NodeCache();
|
|
59
|
+
cache.set('foo', 'bar');
|
|
60
|
+
cache.get('foo'); // 'bar'
|
|
61
|
+
```
|
|
62
|
+
|
|
53
63
|
# Advanced Usage
|
|
54
64
|
|
|
55
65
|
```javascript
|
|
@@ -90,6 +100,7 @@ export type NodeCacheStoreOptions = {
|
|
|
90
100
|
primary?: Keyv; // The primary storage adapter
|
|
91
101
|
secondary?: Keyv; // The secondary storage adapter
|
|
92
102
|
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.
|
|
103
|
+
stats?: boolean; // Default is true, if this is set to false it will not track stats
|
|
93
104
|
};
|
|
94
105
|
```
|
|
95
106
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,48 +15,44 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var src_exports = {};
|
|
32
22
|
__export(src_exports, {
|
|
23
|
+
NodeCache: () => NodeCache,
|
|
33
24
|
NodeCacheErrors: () => NodeCacheErrors,
|
|
34
25
|
NodeCacheStore: () => NodeCacheStore,
|
|
35
|
-
default: () =>
|
|
26
|
+
default: () => src_default
|
|
36
27
|
});
|
|
37
28
|
module.exports = __toCommonJS(src_exports);
|
|
38
|
-
var import_eventemitter3 = __toESM(require("eventemitter3"), 1);
|
|
39
29
|
var import_cacheable2 = require("cacheable");
|
|
30
|
+
var import_hookified2 = require("hookified");
|
|
40
31
|
|
|
41
32
|
// src/store.ts
|
|
42
33
|
var import_cacheable = require("cacheable");
|
|
43
34
|
var import_keyv = require("keyv");
|
|
44
|
-
var
|
|
35
|
+
var import_hookified = require("hookified");
|
|
36
|
+
var NodeCacheStore = class extends import_hookified.Hookified {
|
|
45
37
|
_maxKeys = 0;
|
|
46
38
|
_cache = new import_cacheable.Cacheable({ primary: new import_keyv.Keyv({ store: new import_cacheable.CacheableMemory() }) });
|
|
47
39
|
constructor(options) {
|
|
40
|
+
super();
|
|
48
41
|
if (options) {
|
|
49
42
|
const cacheOptions = {
|
|
50
43
|
ttl: options.ttl,
|
|
51
44
|
primary: options.primary,
|
|
52
|
-
secondary: options.secondary
|
|
45
|
+
secondary: options.secondary,
|
|
46
|
+
stats: options.stats ?? true
|
|
53
47
|
};
|
|
54
48
|
this._cache = new import_cacheable.Cacheable(cacheOptions);
|
|
55
49
|
if (options.maxKeys) {
|
|
56
50
|
this._maxKeys = options.maxKeys;
|
|
57
|
-
if (this._maxKeys > 0) {
|
|
58
|
-
this._cache.stats.enabled = true;
|
|
59
|
-
}
|
|
60
51
|
}
|
|
61
52
|
}
|
|
53
|
+
this._cache.on("error", (error) => {
|
|
54
|
+
this.emit("error", error);
|
|
55
|
+
});
|
|
62
56
|
}
|
|
63
57
|
/**
|
|
64
58
|
* Cacheable instance.
|
|
@@ -243,7 +237,7 @@ var NodeCacheErrors = /* @__PURE__ */ ((NodeCacheErrors2) => {
|
|
|
243
237
|
NodeCacheErrors2["ETTLTYPE"] = "The ttl argument has to be a number or a string for shorthand ttl.";
|
|
244
238
|
return NodeCacheErrors2;
|
|
245
239
|
})(NodeCacheErrors || {});
|
|
246
|
-
var NodeCache = class extends
|
|
240
|
+
var NodeCache = class extends import_hookified2.Hookified {
|
|
247
241
|
options = {
|
|
248
242
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
249
243
|
stdTTL: 0,
|
|
@@ -554,8 +548,10 @@ var NodeCache = class extends import_eventemitter3.default {
|
|
|
554
548
|
return new Error(error);
|
|
555
549
|
}
|
|
556
550
|
};
|
|
551
|
+
var src_default = NodeCache;
|
|
557
552
|
// Annotate the CommonJS export names for ESM import in node:
|
|
558
553
|
0 && (module.exports = {
|
|
554
|
+
NodeCache,
|
|
559
555
|
NodeCacheErrors,
|
|
560
556
|
NodeCacheStore
|
|
561
557
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Hookified } from 'hookified';
|
|
2
2
|
import { Cacheable } from 'cacheable';
|
|
3
3
|
import { Keyv } from 'keyv';
|
|
4
4
|
|
|
@@ -20,8 +20,12 @@ type NodeCacheStoreOptions = {
|
|
|
20
20
|
* [storage-tiering-and-caching](https://github.com/jaredwray/cacheable/tree/main/packages/cacheable#storage-tiering-and-caching)
|
|
21
21
|
*/
|
|
22
22
|
secondary?: Keyv;
|
|
23
|
+
/**
|
|
24
|
+
* Enable stats tracking. This is a breaking change from the original NodeCache.
|
|
25
|
+
*/
|
|
26
|
+
stats?: boolean;
|
|
23
27
|
};
|
|
24
|
-
declare class NodeCacheStore {
|
|
28
|
+
declare class NodeCacheStore extends Hookified {
|
|
25
29
|
private _maxKeys;
|
|
26
30
|
private readonly _cache;
|
|
27
31
|
constructor(options?: NodeCacheStoreOptions);
|
|
@@ -205,7 +209,7 @@ type NodeCacheStats = {
|
|
|
205
209
|
*/
|
|
206
210
|
vsize: number;
|
|
207
211
|
};
|
|
208
|
-
declare class NodeCache extends
|
|
212
|
+
declare class NodeCache extends Hookified {
|
|
209
213
|
readonly options: NodeCacheOptions;
|
|
210
214
|
readonly store: Map<string, any>;
|
|
211
215
|
private _stats;
|
|
@@ -317,4 +321,4 @@ declare class NodeCache extends eventemitter {
|
|
|
317
321
|
private createError;
|
|
318
322
|
}
|
|
319
323
|
|
|
320
|
-
export { NodeCacheErrors, type NodeCacheItem, type NodeCacheOptions, type NodeCacheStats, NodeCacheStore, type NodeCacheStoreOptions, NodeCache as default };
|
|
324
|
+
export { NodeCache, NodeCacheErrors, type NodeCacheItem, type NodeCacheOptions, type NodeCacheStats, NodeCacheStore, type NodeCacheStoreOptions, NodeCache as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Hookified } from 'hookified';
|
|
2
2
|
import { Cacheable } from 'cacheable';
|
|
3
3
|
import { Keyv } from 'keyv';
|
|
4
4
|
|
|
@@ -20,8 +20,12 @@ type NodeCacheStoreOptions = {
|
|
|
20
20
|
* [storage-tiering-and-caching](https://github.com/jaredwray/cacheable/tree/main/packages/cacheable#storage-tiering-and-caching)
|
|
21
21
|
*/
|
|
22
22
|
secondary?: Keyv;
|
|
23
|
+
/**
|
|
24
|
+
* Enable stats tracking. This is a breaking change from the original NodeCache.
|
|
25
|
+
*/
|
|
26
|
+
stats?: boolean;
|
|
23
27
|
};
|
|
24
|
-
declare class NodeCacheStore {
|
|
28
|
+
declare class NodeCacheStore extends Hookified {
|
|
25
29
|
private _maxKeys;
|
|
26
30
|
private readonly _cache;
|
|
27
31
|
constructor(options?: NodeCacheStoreOptions);
|
|
@@ -205,7 +209,7 @@ type NodeCacheStats = {
|
|
|
205
209
|
*/
|
|
206
210
|
vsize: number;
|
|
207
211
|
};
|
|
208
|
-
declare class NodeCache extends
|
|
212
|
+
declare class NodeCache extends Hookified {
|
|
209
213
|
readonly options: NodeCacheOptions;
|
|
210
214
|
readonly store: Map<string, any>;
|
|
211
215
|
private _stats;
|
|
@@ -317,4 +321,4 @@ declare class NodeCache extends eventemitter {
|
|
|
317
321
|
private createError;
|
|
318
322
|
}
|
|
319
323
|
|
|
320
|
-
export { NodeCacheErrors, type NodeCacheItem, type NodeCacheOptions, type NodeCacheStats, NodeCacheStore, type NodeCacheStoreOptions, NodeCache as default };
|
|
324
|
+
export { NodeCache, NodeCacheErrors, type NodeCacheItem, type NodeCacheOptions, type NodeCacheStats, NodeCacheStore, type NodeCacheStoreOptions, NodeCache as default };
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import eventemitter from "eventemitter3";
|
|
3
2
|
import { CacheableMemory as CacheableMemory2, CacheableStats, shorthandToTime } from "cacheable";
|
|
3
|
+
import { Hookified as Hookified2 } from "hookified";
|
|
4
4
|
|
|
5
5
|
// src/store.ts
|
|
6
6
|
import { Cacheable, CacheableMemory } from "cacheable";
|
|
7
7
|
import { Keyv } from "keyv";
|
|
8
|
-
|
|
8
|
+
import { Hookified } from "hookified";
|
|
9
|
+
var NodeCacheStore = class extends Hookified {
|
|
9
10
|
_maxKeys = 0;
|
|
10
11
|
_cache = new Cacheable({ primary: new Keyv({ store: new CacheableMemory() }) });
|
|
11
12
|
constructor(options) {
|
|
13
|
+
super();
|
|
12
14
|
if (options) {
|
|
13
15
|
const cacheOptions = {
|
|
14
16
|
ttl: options.ttl,
|
|
15
17
|
primary: options.primary,
|
|
16
|
-
secondary: options.secondary
|
|
18
|
+
secondary: options.secondary,
|
|
19
|
+
stats: options.stats ?? true
|
|
17
20
|
};
|
|
18
21
|
this._cache = new Cacheable(cacheOptions);
|
|
19
22
|
if (options.maxKeys) {
|
|
20
23
|
this._maxKeys = options.maxKeys;
|
|
21
|
-
if (this._maxKeys > 0) {
|
|
22
|
-
this._cache.stats.enabled = true;
|
|
23
|
-
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
this._cache.on("error", (error) => {
|
|
27
|
+
this.emit("error", error);
|
|
28
|
+
});
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Cacheable instance.
|
|
@@ -207,7 +210,7 @@ var NodeCacheErrors = /* @__PURE__ */ ((NodeCacheErrors2) => {
|
|
|
207
210
|
NodeCacheErrors2["ETTLTYPE"] = "The ttl argument has to be a number or a string for shorthand ttl.";
|
|
208
211
|
return NodeCacheErrors2;
|
|
209
212
|
})(NodeCacheErrors || {});
|
|
210
|
-
var NodeCache = class extends
|
|
213
|
+
var NodeCache = class extends Hookified2 {
|
|
211
214
|
options = {
|
|
212
215
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
213
216
|
stdTTL: 0,
|
|
@@ -518,8 +521,10 @@ var NodeCache = class extends eventemitter {
|
|
|
518
521
|
return new Error(error);
|
|
519
522
|
}
|
|
520
523
|
};
|
|
524
|
+
var src_default = NodeCache;
|
|
521
525
|
export {
|
|
526
|
+
NodeCache,
|
|
522
527
|
NodeCacheErrors,
|
|
523
528
|
NodeCacheStore,
|
|
524
|
-
|
|
529
|
+
src_default as default
|
|
525
530
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cacheable/node-cache",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Simple and Maintained fast NodeJS internal caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"cacheable": "^1.8.1",
|
|
44
|
-
"
|
|
44
|
+
"hookified": "^1.5.1",
|
|
45
45
|
"keyv": "^5.2.1"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|