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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ 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.0](https://github.com/avoidwork/tiny-lru/compare/13.0.1...13.1.0)

- 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)
- build(deps-dev): bump rollup from 4.63.3 to 4.63.4 [`#494`](https://github.com/avoidwork/tiny-lru/pull/494)
- build(deps-dev): bump rollup from 4.63.2 to 4.63.3 [`#492`](https://github.com/avoidwork/tiny-lru/pull/492)
- build(deps-dev): bump oxlint from 1.82.0 to 1.83.0 [`#491`](https://github.com/avoidwork/tiny-lru/pull/491)
- build(deps-dev): bump rollup from 4.63.1 to 4.63.2 [`#490`](https://github.com/avoidwork/tiny-lru/pull/490)

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

> 15 September 2026

- chore: release v13.0.1 [`#489`](https://github.com/avoidwork/tiny-lru/pull/489)
- fix: LRU edge cases in TTL handling and factory validation [`#488`](https://github.com/avoidwork/tiny-lru/pull/488)
- build(deps-dev): bump tinybench from 6.1.6 to 6.2.0 [`#486`](https://github.com/avoidwork/tiny-lru/pull/486)
- build(deps-dev): bump oxlint from 1.81.0 to 1.82.0 [`#484`](https://github.com/avoidwork/tiny-lru/pull/484)
Expand Down
25 changes: 16 additions & 9 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.0.1
* @version 13.1.0
*/
'use strict';

Expand Down Expand Up @@ -321,17 +321,16 @@ class LRU {

/**
* Returns an array of all keys in the cache, ordered from least to most recently used.
* Expired items are skipped, consistent with entries(), values(), and toJSON().
*
* @returns {string[]} Array of keys in LRU order.
*/
keys() {
const result = Array.from({ length: this.size });
let x = this.first;
let i = 0;

while (x !== null) {
result[i++] = x.key;
x = x.next;
const result = [];
for (let x = this.first; x !== null; x = x.next) {
if (!this.#isExpired(x)) {
result.push(x.key);
}
}

return result;
Expand Down Expand Up @@ -557,9 +556,10 @@ class LRU {
* Remove expired items without affecting LRU order.
* Unlike get(), this does not move items to the end.
*
* @param {boolean} [fireOnEvict=false] - When true, invokes the onEvict callback for each removed item.
* @returns {number} Number of expired items removed.
*/
cleanup() {
cleanup(fireOnEvict = false) {
if (this.ttl === 0 || this.size === 0) {
return 0;
}
Expand All @@ -577,6 +577,13 @@ class LRU {
this.#unlink(x);
x.prev = null;
x.next = null;
if (fireOnEvict && this.#onEvict !== null) {
this.#onEvict({
key: x.key,
value: x.value,
expiry: x.expiry,
});
}
}
}
x = next;
Expand Down
25 changes: 16 additions & 9 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.0.1
* @version 13.1.0
*/
/**
* A high-performance Least Recently Used (LRU) cache implementation with optional TTL support.
Expand Down Expand Up @@ -319,17 +319,16 @@ class LRU {

/**
* Returns an array of all keys in the cache, ordered from least to most recently used.
* Expired items are skipped, consistent with entries(), values(), and toJSON().
*
* @returns {string[]} Array of keys in LRU order.
*/
keys() {
const result = Array.from({ length: this.size });
let x = this.first;
let i = 0;

while (x !== null) {
result[i++] = x.key;
x = x.next;
const result = [];
for (let x = this.first; x !== null; x = x.next) {
if (!this.#isExpired(x)) {
result.push(x.key);
}
}

return result;
Expand Down Expand Up @@ -555,9 +554,10 @@ class LRU {
* Remove expired items without affecting LRU order.
* Unlike get(), this does not move items to the end.
*
* @param {boolean} [fireOnEvict=false] - When true, invokes the onEvict callback for each removed item.
* @returns {number} Number of expired items removed.
*/
cleanup() {
cleanup(fireOnEvict = false) {
if (this.ttl === 0 || this.size === 0) {
return 0;
}
Expand All @@ -575,6 +575,13 @@ class LRU {
this.#unlink(x);
x.prev = null;
x.next = null;
if (fireOnEvict && this.#onEvict !== null) {
this.#onEvict({
key: x.key,
value: x.value,
expiry: x.expiry,
});
}
}
}
x = next;
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.0.1",
"version": "13.1.0",
"description": "A fast, lightweight LRU (Least Recently Used) cache for JavaScript with O(1) operations and optional TTL support.",
"keywords": [
"LRU",
Expand Down
Loading