@nxtedition/cache 2.1.1 → 2.1.2

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.
Files changed (2) hide show
  1. package/lib/memory.js +2 -2
  2. package/package.json +2 -2
package/lib/memory.js CHANGED
@@ -78,7 +78,7 @@ export class MemoryCache {
78
78
  #delete(entry ) {
79
79
  this.#map.delete(entry.key)
80
80
 
81
- this.#size -= entry.size
81
+ this.#size -= entry.size ?? 0
82
82
  this.#count -= 1
83
83
 
84
84
  const tmp = this.#arr.pop()
@@ -107,7 +107,7 @@ export class MemoryCache {
107
107
  }
108
108
 
109
109
  #prune() {
110
- while (this.#size > this.#maxSize || this.#count > this.#maxCount) {
110
+ while (this.#arr.length > 0 && (this.#size > this.#maxSize || this.#count > this.#maxCount)) {
111
111
  const e1 = this.#arr[(Math.random() * this.#arr.length) | 0]
112
112
  const e2 = this.#arr[(Math.random() * this.#arr.length) | 0]
113
113
  const e = e2.counter > e1.counter ? e1 : e2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/cache",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -30,5 +30,5 @@
30
30
  "tsd": "^0.33.0",
31
31
  "typescript": "^5.9.3"
32
32
  },
33
- "gitHead": "3b68f317345f4e74459689d2a82fb0a5cc785d1f"
33
+ "gitHead": "f0aff304c4a0a7246ea0cb34f8d8b3839dc11e81"
34
34
  }