Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [13.1.1](https://github.com/avoidwork/tiny-lru/compare/13.1.0...13.1.1)

- fix: preserve cleanup list links across TTL expiry [`#510`](https://github.com/avoidwork/tiny-lru/pull/510)
- build(deps-dev): bump rollup from 4.64.7 to 4.64.9 [`#514`](https://github.com/avoidwork/tiny-lru/pull/514)
- build(deps-dev): bump oxlint from 1.87.0 to 1.88.0 [`#513`](https://github.com/avoidwork/tiny-lru/pull/513)
- build(deps-dev): bump rollup from 4.64.5 to 4.64.7 [`#512`](https://github.com/avoidwork/tiny-lru/pull/512)
- build(deps-dev): bump oxfmt from 0.72.0 to 0.73.0 [`#511`](https://github.com/avoidwork/tiny-lru/pull/511)
- build(deps-dev): bump rollup from 4.64.3 to 4.64.5 [`#509`](https://github.com/avoidwork/tiny-lru/pull/509)
- build(deps-dev): bump tinybench from 6.2.1 to 6.2.2 [`#508`](https://github.com/avoidwork/tiny-lru/pull/508)
- build(deps-dev): bump rollup from 4.64.1 to 4.64.3 [`#507`](https://github.com/avoidwork/tiny-lru/pull/507)
- chore: update dev dependencies to latest versions [`#506`](https://github.com/avoidwork/tiny-lru/pull/506)
- build(deps-dev): bump rollup from 4.63.6 to 4.64.0 [`#505`](https://github.com/avoidwork/tiny-lru/pull/505)
- build(deps-dev): bump rollup from 4.63.5 to 4.63.6 [`#504`](https://github.com/avoidwork/tiny-lru/pull/504)
- build(deps-dev): bump oxlint from 1.85.0 to 1.86.0 [`#503`](https://github.com/avoidwork/tiny-lru/pull/503)
- build(deps-dev): bump rollup from 4.63.4 to 4.63.5 [`#501`](https://github.com/avoidwork/tiny-lru/pull/501)
- build(deps-dev): bump auto-changelog from 2.6.1 to 2.7.0 [`#500`](https://github.com/avoidwork/tiny-lru/pull/500)

#### [13.1.0](https://github.com/avoidwork/tiny-lru/compare/13.0.1...13.1.0)

> 26 September 2026

- chore: release v13.1.0 [`#499`](https://github.com/avoidwork/tiny-lru/pull/499)
- feat: add fireOnEvict option to cleanup() [`#498`](https://github.com/avoidwork/tiny-lru/pull/498)
- docs: correct README, API docs, and type definitions [`#497`](https://github.com/avoidwork/tiny-lru/pull/497)
- build(deps-dev): bump oxlint from 1.83.0 to 1.85.0 [`#496`](https://github.com/avoidwork/tiny-lru/pull/496)
Expand Down
45 changes: 4 additions & 41 deletions dist/tiny-lru.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 13.1.0
* @version 13.1.1
*/
'use strict';

Expand Down Expand Up @@ -57,7 +57,7 @@ class LRU {
* @returns {LRU} The LRU instance for method chaining.
*/
clear() {
for (let x = this.first; x !== null; ) {
for (let x = this.first; x !== null;) {
const next = x.next;
x.prev = null;
x.next = null;
Expand Down Expand Up @@ -481,7 +481,7 @@ class LRU {
* @returns {LRU} The LRU instance for method chaining.
*/
forEach(callback, thisArg) {
for (let x = this.first; x !== null; ) {
for (let x = this.first; x !== null;) {
const next = x.next;
if (!this.#isExpired(x)) {
callback.call(thisArg, x.value, x.key, this);
Expand Down Expand Up @@ -566,7 +566,7 @@ class LRU {

let removed = 0;

for (let x = this.first; x !== null; ) {
for (let x = this.first; x !== null;) {
const next = x.next;
if (this.#isExpired(x)) {
const key = x.key;
Expand All @@ -589,10 +589,6 @@ class LRU {
x = next;
}

if (removed > 0) {
this.#rebuildList();
}

return removed;
}

Expand Down Expand Up @@ -715,39 +711,6 @@ class LRU {

return { valid, expired, noTTL: [] };
}

/**
* Rebuild the doubly-linked list after cleanup by deleting expired items.
* This removes nodes that were deleted during cleanup.
*
* @private
*/
#rebuildList() {
if (this.size === 0) {
this.first = null;
this.last = null;
return;
}

const keys = this.keys();
this.first = null;
this.last = null;

for (let i = 0; i < keys.length; i++) {
const item = this.items[keys[i]];
if (item !== null && item !== undefined) {
if (this.first === null) {
this.first = item;
item.prev = null;
} else {
item.prev = this.last;
this.last.next = item;
}
item.next = null;
this.last = item;
}
}
}
}

/**
Expand Down
45 changes: 4 additions & 41 deletions dist/tiny-lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 13.1.0
* @version 13.1.1
*/
/**
* A high-performance Least Recently Used (LRU) cache implementation with optional TTL support.
Expand Down Expand Up @@ -55,7 +55,7 @@ class LRU {
* @returns {LRU} The LRU instance for method chaining.
*/
clear() {
for (let x = this.first; x !== null; ) {
for (let x = this.first; x !== null;) {
const next = x.next;
x.prev = null;
x.next = null;
Expand Down Expand Up @@ -479,7 +479,7 @@ class LRU {
* @returns {LRU} The LRU instance for method chaining.
*/
forEach(callback, thisArg) {
for (let x = this.first; x !== null; ) {
for (let x = this.first; x !== null;) {
const next = x.next;
if (!this.#isExpired(x)) {
callback.call(thisArg, x.value, x.key, this);
Expand Down Expand Up @@ -564,7 +564,7 @@ class LRU {

let removed = 0;

for (let x = this.first; x !== null; ) {
for (let x = this.first; x !== null;) {
const next = x.next;
if (this.#isExpired(x)) {
const key = x.key;
Expand All @@ -587,10 +587,6 @@ class LRU {
x = next;
}

if (removed > 0) {
this.#rebuildList();
}

return removed;
}

Expand Down Expand Up @@ -713,39 +709,6 @@ class LRU {

return { valid, expired, noTTL: [] };
}

/**
* Rebuild the doubly-linked list after cleanup by deleting expired items.
* This removes nodes that were deleted during cleanup.
*
* @private
*/
#rebuildList() {
if (this.size === 0) {
this.first = null;
this.last = null;
return;
}

const keys = this.keys();
this.first = null;
this.last = null;

for (let i = 0; i < keys.length; i++) {
const item = this.items[keys[i]];
if (item !== null && item !== undefined) {
if (this.first === null) {
this.first = item;
item.prev = null;
} else {
item.prev = this.last;
this.last.next = item;
}
item.next = null;
this.last = item;
}
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/tiny-lru.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/tiny-lru.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-lru",
"version": "13.1.0",
"version": "13.1.1",
"description": "A fast, lightweight LRU (Least Recently Used) cache for JavaScript with O(1) operations and optional TTL support.",
"keywords": [
"LRU",
Expand Down
Loading