Skip to content

Commit 4cba0a2

Browse files
committed
Rename resetTtl to resetTTL for consistent TTL naming
1 parent f2fc84b commit 4cba0a2

10 files changed

Lines changed: 63 additions & 57 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const cache4 = lru(100, 60000, true); // with resetTtl enabled
124124
| ---------- | --------- | ------- | ---------------------------------------------------------------- |
125125
| `max` | `number` | `1000` | Maximum items. `0` = unlimited. Must be >= 0. |
126126
| `ttl` | `number` | `0` | Time-to-live in milliseconds. `0` = no expiration. Must be >= 0. |
127-
| `resetTtl` | `boolean` | `false` | Reset TTL when updating existing items via `set()` |
127+
| `resetTTL` | `boolean` | `false` | Reset TTL when updating existing items via `set()` |
128128

129129
**Returns:** `LRU` - New cache instance
130130

@@ -146,7 +146,7 @@ const cache = new LRU(100, 5000);
146146
| ---------- | --------- | ------- | -------------------------------------------------- |
147147
| `max` | `number` | `0` | Maximum items. `0` = unlimited. |
148148
| `ttl` | `number` | `0` | Time-to-live in milliseconds. `0` = no expiration. |
149-
| `resetTtl` | `boolean` | `false` | Reset TTL when updating via `set()` |
149+
| `resetTTL` | `boolean` | `false` | Reset TTL when updating via `set()` |
150150

151151
### Properties
152152

@@ -155,7 +155,7 @@ const cache = new LRU(100, 5000);
155155
| `first` | `object` \| `null` | Least recently used item (node with `key`, `value`, `prev`, `next`, `expiry`) |
156156
| `last` | `object` \| `null` | Most recently used item (node with `key`, `value`, `prev`, `next`, `expiry`) |
157157
| `max` | `number` | Maximum items allowed |
158-
| `resetTtl`| `boolean` | Whether TTL resets on `set()` updates |
158+
| `resetTTL`| `boolean` | Whether TTL resets on `set()` updates |
159159
| `size` | `number` | Current number of items |
160160
| `ttl` | `number` | Time-to-live in milliseconds |
161161

dist/tiny-lru.cjs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class LRU {
2525
* @constructor
2626
* @param {number} [max=0] - Maximum number of items to store. 0 means unlimited.
2727
* @param {number} [ttl=0] - Time to live in milliseconds. 0 means no expiration.
28-
* @param {boolean} [resetTtl=false] - Whether to reset TTL when updating existing items via set().
28+
* @param {boolean} [resetTTL=false] - Whether to reset TTL when updating existing items via set().
2929
*/
30-
constructor(max = 0, ttl = 0, resetTtl = false) {
30+
constructor(max = 0, ttl = 0, resetTTL = false) {
3131
this.first = null;
3232
this.items = Object.create(null);
3333
this.last = null;
3434
this.max = max;
35-
this.resetTtl = resetTtl;
35+
this.resetTTL = resetTTL;
3636
this.size = 0;
3737
this.ttl = ttl;
3838
this.#stats = { hits: 0, misses: 0, sets: 0, deletes: 0, evictions: 0 };
@@ -297,7 +297,7 @@ class LRU {
297297

298298
if (item !== undefined) {
299299
item.value = value;
300-
if (this.resetTtl) {
300+
if (this.resetTTL) {
301301
item.expiry = this.ttl > 0 ? Date.now() + this.ttl : this.ttl;
302302
}
303303
this.moveToEnd(item);
@@ -345,7 +345,7 @@ class LRU {
345345
if (item !== undefined) {
346346
item.value = value;
347347

348-
if (this.resetTtl) {
348+
if (this.resetTTL) {
349349
item.expiry = this.ttl > 0 ? Date.now() + this.ttl : this.ttl;
350350
}
351351

@@ -661,11 +661,11 @@ class LRU {
661661
* @function lru
662662
* @param {number} [max=1000] - Maximum number of items to store. Must be >= 0. Use 0 for unlimited size.
663663
* @param {number} [ttl=0] - Time to live in milliseconds. Must be >= 0. Use 0 for no expiration.
664-
* @param {boolean} [resetTtl=false] - Whether to reset TTL when updating existing items via set().
664+
* @param {boolean} [resetTTL=false] - Whether to reset TTL when updating existing items via set().
665665
* @returns {LRU} A new LRU cache instance.
666666
* @throws {TypeError} When parameters are invalid (negative numbers or wrong types).
667667
*/
668-
function lru(max = 1000, ttl = 0, resetTtl = false) {
668+
function lru(max = 1000, ttl = 0, resetTTL = false) {
669669
if (isNaN(max) || max < 0) {
670670
throw new TypeError("Invalid max value");
671671
}
@@ -674,11 +674,11 @@ function lru(max = 1000, ttl = 0, resetTtl = false) {
674674
throw new TypeError("Invalid ttl value");
675675
}
676676

677-
if (typeof resetTtl !== "boolean") {
678-
throw new TypeError("Invalid resetTtl value");
677+
if (typeof resetTTL !== "boolean") {
678+
throw new TypeError("Invalid resetTTL value");
679679
}
680680

681-
return new LRU(max, ttl, resetTtl);
681+
return new LRU(max, ttl, resetTTL);
682682
}
683683

684684
exports.LRU = LRU;

dist/tiny-lru.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class LRU {
2323
* @constructor
2424
* @param {number} [max=0] - Maximum number of items to store. 0 means unlimited.
2525
* @param {number} [ttl=0] - Time to live in milliseconds. 0 means no expiration.
26-
* @param {boolean} [resetTtl=false] - Whether to reset TTL when updating existing items via set().
26+
* @param {boolean} [resetTTL=false] - Whether to reset TTL when updating existing items via set().
2727
*/
28-
constructor(max = 0, ttl = 0, resetTtl = false) {
28+
constructor(max = 0, ttl = 0, resetTTL = false) {
2929
this.first = null;
3030
this.items = Object.create(null);
3131
this.last = null;
3232
this.max = max;
33-
this.resetTtl = resetTtl;
33+
this.resetTTL = resetTTL;
3434
this.size = 0;
3535
this.ttl = ttl;
3636
this.#stats = { hits: 0, misses: 0, sets: 0, deletes: 0, evictions: 0 };
@@ -295,7 +295,7 @@ class LRU {
295295

296296
if (item !== undefined) {
297297
item.value = value;
298-
if (this.resetTtl) {
298+
if (this.resetTTL) {
299299
item.expiry = this.ttl > 0 ? Date.now() + this.ttl : this.ttl;
300300
}
301301
this.moveToEnd(item);
@@ -343,7 +343,7 @@ class LRU {
343343
if (item !== undefined) {
344344
item.value = value;
345345

346-
if (this.resetTtl) {
346+
if (this.resetTTL) {
347347
item.expiry = this.ttl > 0 ? Date.now() + this.ttl : this.ttl;
348348
}
349349

@@ -659,11 +659,11 @@ class LRU {
659659
* @function lru
660660
* @param {number} [max=1000] - Maximum number of items to store. Must be >= 0. Use 0 for unlimited size.
661661
* @param {number} [ttl=0] - Time to live in milliseconds. Must be >= 0. Use 0 for no expiration.
662-
* @param {boolean} [resetTtl=false] - Whether to reset TTL when updating existing items via set().
662+
* @param {boolean} [resetTTL=false] - Whether to reset TTL when updating existing items via set().
663663
* @returns {LRU} A new LRU cache instance.
664664
* @throws {TypeError} When parameters are invalid (negative numbers or wrong types).
665665
*/
666-
function lru(max = 1000, ttl = 0, resetTtl = false) {
666+
function lru(max = 1000, ttl = 0, resetTTL = false) {
667667
if (isNaN(max) || max < 0) {
668668
throw new TypeError("Invalid max value");
669669
}
@@ -672,9 +672,9 @@ function lru(max = 1000, ttl = 0, resetTtl = false) {
672672
throw new TypeError("Invalid ttl value");
673673
}
674674

675-
if (typeof resetTtl !== "boolean") {
676-
throw new TypeError("Invalid resetTtl value");
675+
if (typeof resetTTL !== "boolean") {
676+
throw new TypeError("Invalid resetTTL value");
677677
}
678678

679-
return new LRU(max, ttl, resetTtl);
679+
return new LRU(max, ttl, resetTTL);
680680
}export{LRU,lru};

dist/tiny-lru.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tiny-lru.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/API.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Complete API documentation for tiny-lru.
1010
- [first](#first)
1111
- [last](#last)
1212
- [max](#max)
13-
- [resetTtl](#resetttl)
13+
- [resetTTL](#resetttl)
1414
- [size](#size)
1515
- [ttl](#ttl)
1616
- [Methods](#methods)
@@ -61,7 +61,7 @@ const cache = lru(100, 5000, true);
6161
| ---------- | --------- | ------- | ---------------------------------------------------------------- |
6262
| `max` | `number` | `1000` | Maximum items. `0` = unlimited. Must be >= 0. |
6363
| `ttl` | `number` | `0` | Time-to-live in milliseconds. `0` = no expiration. Must be >= 0. |
64-
| `resetTtl` | `boolean` | `false` | Reset TTL when updating existing items via `set()` |
64+
| `resetTTL` | `boolean` | `false` | Reset TTL when updating existing items via `set()` |
6565

6666
**Returns:** `LRU` - New cache instance
6767

@@ -93,7 +93,7 @@ const cache = new LRU(100, 5000, true);
9393
| ---------- | --------- | ------- | -------------------------------------------------- |
9494
| `max` | `number` | `0` | Maximum items. `0` = unlimited. |
9595
| `ttl` | `number` | `0` | Time-to-live in milliseconds. `0` = no expiration. |
96-
| `resetTtl` | `boolean` | `false` | Reset TTL when updating via `set()` |
96+
| `resetTTL` | `boolean` | `false` | Reset TTL when updating via `set()` |
9797

9898
---
9999

@@ -129,7 +129,7 @@ const cache = lru(100);
129129
console.log(cache.max); // 100
130130
```
131131

132-
### `resetTtl`
132+
### `resetTTL`
133133

134134
`boolean` - Whether TTL resets on `set()` updates.
135135

docs/TECHNICAL_DOCUMENTATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ graph TD
5656
- `max`: Maximum cache size (0 = unlimited)
5757
- `size`: Current number of items
5858
- `ttl`: Time-to-live in milliseconds (0 = no expiration)
59-
- `resetTtl`: Whether to reset TTL on `set()` and `setWithEvicted()` operations (not on `get()`)
59+
- `resetTTL`: Whether to reset TTL on `set()` and `setWithEvicted()` operations (not on `get()`)
6060

6161
## Data Flow
6262

0 commit comments

Comments
 (0)