@thi.ng/cache 2.1.87 → 2.1.89

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-31T09:44:23Z
3
+ - **Last updated**: 2024-01-26T18:03:04Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.1.89](https://github.com/thi-ng/umbrella/tree/@thi.ng/cache@2.1.89) (2024-01-26)
13
+
14
+ #### 🩹 Bug fixes
15
+
16
+ - attempt to add element bigger than "maxsize" blocks addition of any new elements to the cache ([3c855ef](https://github.com/thi-ng/umbrella/commit/3c855ef))
17
+
12
18
  ### [2.1.76](https://github.com/thi-ng/umbrella/tree/@thi.ng/cache@2.1.76) (2023-11-09)
13
19
 
14
20
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -76,7 +76,7 @@ For Node.js REPL:
76
76
  const cache = await import("@thi.ng/cache");
77
77
  ```
78
78
 
79
- Package sizes (brotli'd, pre-treeshake): ESM: 1.06 KB
79
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.08 KB
80
80
 
81
81
  ## Dependencies
82
82
 
@@ -246,4 +246,4 @@ If this project contributes to an academic publication, please cite it as:
246
246
 
247
247
  ## License
248
248
 
249
- © 2018 - 2023 Karsten Schmidt // Apache License 2.0
249
+ © 2018 - 2024 Karsten Schmidt // Apache License 2.0
package/lru.js CHANGED
@@ -81,8 +81,13 @@ class LRUCache {
81
81
  set(key, value) {
82
82
  const size = this.opts.ksize(key) + this.opts.vsize(value);
83
83
  const e = this.map.get(key);
84
- this._size += Math.max(0, size - (e ? e.value.s : 0));
85
- this.ensureSize() && this.doSetEntry(e, key, value, size);
84
+ const additionalSize = Math.max(0, size - (e ? e.value.s : 0));
85
+ this._size += additionalSize;
86
+ if (this.ensureSize()) {
87
+ this.doSetEntry(e, key, value, size);
88
+ } else {
89
+ this._size -= additionalSize;
90
+ }
86
91
  return value;
87
92
  }
88
93
  into(pairs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/cache",
3
- "version": "2.1.87",
3
+ "version": "2.1.89",
4
4
  "description": "In-memory cache implementations with ES6 Map-like API and different eviction strategies",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,9 +35,9 @@
35
35
  "test": "bun test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.9.16",
39
- "@thi.ng/dcons": "^3.2.82",
40
- "@thi.ng/transducers": "^8.8.20"
38
+ "@thi.ng/api": "^8.9.18",
39
+ "@thi.ng/dcons": "^3.2.84",
40
+ "@thi.ng/transducers": "^8.8.22"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.39.0",
@@ -90,5 +90,5 @@
90
90
  ],
91
91
  "year": 2018
92
92
  },
93
- "gitHead": "b3db173682e1148cf08a6bd907b8d90b47b7c066\n"
93
+ "gitHead": "7426e2ae6fca5482c6eaf649872296fc89955374\n"
94
94
  }
package/tlru.d.ts CHANGED
@@ -34,5 +34,6 @@ export declare class TLRUCache<K, V> extends LRUCache<K, V> {
34
34
  getSet(key: K, retrieve: Fn0<Promise<V>>, ttl?: number): Promise<V>;
35
35
  prune(): void;
36
36
  protected ensureSize(): boolean;
37
+ protected doSetTlruEntry(e: ConsCell<TLRUCacheEntry<K, V>> | undefined, k: K, v: V, s: number, t: number): void;
37
38
  }
38
39
  //# sourceMappingURL=tlru.d.ts.map
package/tlru.js CHANGED
@@ -23,23 +23,13 @@ class TLRUCache extends LRUCache {
23
23
  set(key, value, ttl = this.opts.ttl) {
24
24
  const size = this.opts.ksize(key) + this.opts.vsize(value);
25
25
  const e = this.map.get(key);
26
- this._size += Math.max(0, size - (e ? e.value.s : 0));
26
+ const additionalSize = Math.max(0, size - (e ? e.value.s : 0));
27
+ this._size += additionalSize;
27
28
  if (this.ensureSize()) {
28
29
  const t = Date.now() + ttl;
29
- if (e) {
30
- e.value.v = value;
31
- e.value.s = size;
32
- e.value.t = t;
33
- this.items.asTail(e);
34
- } else {
35
- this.items.push({
36
- k: key,
37
- v: value,
38
- s: size,
39
- t
40
- });
41
- this.map.set(key, this.items.tail);
42
- }
30
+ this.doSetTlruEntry(e, key, value, size, t);
31
+ } else {
32
+ this._size -= additionalSize;
43
33
  }
44
34
  return value;
45
35
  }
@@ -73,6 +63,17 @@ class TLRUCache extends LRUCache {
73
63
  }
74
64
  return super.ensureSize();
75
65
  }
66
+ doSetTlruEntry(e, k, v, s, t) {
67
+ if (e) {
68
+ e.value.v = v;
69
+ e.value.s = s;
70
+ e.value.t = t;
71
+ this.items.asTail(e);
72
+ } else {
73
+ this.items.push({ k, v, s, t });
74
+ this.map.set(k, this.items.tail);
75
+ }
76
+ }
76
77
  }
77
78
  export {
78
79
  TLRUCache