@cacheable/node-cache 1.5.1 → 1.5.3

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
@@ -141,7 +141,7 @@ export type NodeCacheOptions = {
141
141
  stdTTL?: number; // The standard ttl as number in seconds for every generated cache element. 0 = unlimited. If string, it will be parsed as shorthand and default to milliseconds if it is a number as a string.
142
142
  checkperiod?: number; // Default is 600, 0 means no periodic check
143
143
  useClones?: boolean; // Default is true
144
- deleteOnExpire?: boolean; // Default is true, if this is set to true it will delete the key when it expires.
144
+ deleteOnExpire?: boolean; // Default is true, if false it will keep the key and not delete during an interval check and the value on get() will be undefined
145
145
  maxKeys?: number; // Default is -1 (unlimited). If this is set it will throw and error if you try to set more keys than the max.
146
146
  };
147
147
  ```
package/dist/index.cjs CHANGED
@@ -18,14 +18,14 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  NodeCache: () => NodeCache,
24
24
  NodeCacheErrors: () => NodeCacheErrors,
25
25
  NodeCacheStore: () => NodeCacheStore,
26
- default: () => src_default
26
+ default: () => index_default
27
27
  });
28
- module.exports = __toCommonJS(src_exports);
28
+ module.exports = __toCommonJS(index_exports);
29
29
  var import_cacheable2 = require("cacheable");
30
30
  var import_hookified2 = require("hookified");
31
31
 
@@ -530,7 +530,10 @@ var NodeCache = class extends import_hookified2.Hookified {
530
530
  checkData() {
531
531
  for (const [key, value] of this.store.entries()) {
532
532
  if (value.ttl > 0 && value.ttl < Date.now()) {
533
- this.del(key);
533
+ if (this.options.deleteOnExpire) {
534
+ this.del(key);
535
+ }
536
+ this.emit("expired", this.formatKey(key), value.value);
534
537
  }
535
538
  }
536
539
  }
@@ -548,7 +551,7 @@ var NodeCache = class extends import_hookified2.Hookified {
548
551
  return new Error(error);
549
552
  }
550
553
  };
551
- var src_default = NodeCache;
554
+ var index_default = NodeCache;
552
555
  // Annotate the CommonJS export names for ESM import in node:
553
556
  0 && (module.exports = {
554
557
  NodeCache,
package/dist/index.d.cts CHANGED
@@ -158,7 +158,7 @@ type NodeCacheOptions = {
158
158
  */
159
159
  useClones?: boolean;
160
160
  /**
161
- * Delete all expired items at the set interval. Default is true.
161
+ * Delete expired items during an interval check or a single item on a get request. Default is true.
162
162
  */
163
163
  deleteOnExpire?: boolean;
164
164
  /**
package/dist/index.d.ts CHANGED
@@ -158,7 +158,7 @@ type NodeCacheOptions = {
158
158
  */
159
159
  useClones?: boolean;
160
160
  /**
161
- * Delete all expired items at the set interval. Default is true.
161
+ * Delete expired items during an interval check or a single item on a get request. Default is true.
162
162
  */
163
163
  deleteOnExpire?: boolean;
164
164
  /**
package/dist/index.js CHANGED
@@ -503,7 +503,10 @@ var NodeCache = class extends Hookified2 {
503
503
  checkData() {
504
504
  for (const [key, value] of this.store.entries()) {
505
505
  if (value.ttl > 0 && value.ttl < Date.now()) {
506
- this.del(key);
506
+ if (this.options.deleteOnExpire) {
507
+ this.del(key);
508
+ }
509
+ this.emit("expired", this.formatKey(key), value.value);
507
510
  }
508
511
  }
509
512
  }
@@ -521,10 +524,10 @@ var NodeCache = class extends Hookified2 {
521
524
  return new Error(error);
522
525
  }
523
526
  };
524
- var src_default = NodeCache;
527
+ var index_default = NodeCache;
525
528
  export {
526
529
  NodeCache,
527
530
  NodeCacheErrors,
528
531
  NodeCacheStore,
529
- src_default as default
532
+ index_default as default
530
533
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cacheable/node-cache",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Simple and Maintained fast NodeJS internal caching",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -31,18 +31,18 @@
31
31
  "cacheable-node"
32
32
  ],
33
33
  "devDependencies": {
34
- "@types/node": "^22.8.1",
35
- "@vitest/coverage-v8": "^2.1.3",
34
+ "@types/node": "^22.13.9",
35
+ "@vitest/coverage-v8": "^3.0.7",
36
36
  "rimraf": "^6.0.1",
37
- "tsup": "^8.3.5",
38
- "typescript": "^5.6.3",
39
- "vitest": "^2.1.3",
40
- "xo": "^0.59.3"
37
+ "tsup": "^8.4.0",
38
+ "typescript": "^5.8.2",
39
+ "vitest": "^3.0.7",
40
+ "xo": "^0.60.0"
41
41
  },
42
42
  "dependencies": {
43
- "cacheable": "^1.8.1",
44
- "hookified": "^1.5.1",
45
- "keyv": "^5.2.1"
43
+ "hookified": "^1.7.1",
44
+ "keyv": "^5.3.1",
45
+ "cacheable": "^1.8.9"
46
46
  },
47
47
  "files": [
48
48
  "dist",
@@ -50,6 +50,7 @@
50
50
  ],
51
51
  "scripts": {
52
52
  "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
53
+ "prepublish": "pnpm build",
53
54
  "test": "xo --fix && vitest run --coverage",
54
55
  "test:ci": "xo && vitest run",
55
56
  "clean": "rimraf ./dist ./coverage ./node_modules"