@thi.ng/cache 2.1.88 → 2.1.91

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**: 2024-01-23T15:58:27Z
3
+ - **Last updated**: 2024-01-29T21:04:46Z
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
@@ -7,9 +7,13 @@
7
7
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/cache.svg)
8
8
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
9
9
 
10
- This is a standalone project, maintained as part of the
11
- [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo and
12
- anti-framework.
10
+ > [!NOTE]
11
+ > This is one of 189 standalone projects, maintained as part
12
+ > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
13
+ > and anti-framework.
14
+ >
15
+ > 🚀 Help me to work full-time on these projects by [sponsoring me on
16
+ > GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
13
17
 
14
18
  - [About](#about)
15
19
  - [Available strategies](#available-strategies)
@@ -76,7 +80,7 @@ For Node.js REPL:
76
80
  const cache = await import("@thi.ng/cache");
77
81
  ```
78
82
 
79
- Package sizes (brotli'd, pre-treeshake): ESM: 1.06 KB
83
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.08 KB
80
84
 
81
85
  ## Dependencies
82
86
 
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.88",
3
+ "version": "2.1.91",
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.17",
39
- "@thi.ng/dcons": "^3.2.83",
40
- "@thi.ng/transducers": "^8.8.21"
38
+ "@thi.ng/api": "^8.9.20",
39
+ "@thi.ng/dcons": "^3.2.86",
40
+ "@thi.ng/transducers": "^8.8.24"
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": "417b5a7ea7bd54a3b4f086fe0fc2ce8e8933c9b2\n"
93
+ "gitHead": "3fa30b2dc2de762f24fd64b881b68d4da33d4c38\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