Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: isaacs/node-lru-cache
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.2.2
Choose a base ref
...
head repository: isaacs/node-lru-cache
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.3.0
Choose a head ref
  • 11 commits
  • 13 files changed
  • 3 contributors

Commits on Jun 27, 2024

  1. chore: updated 'set' method signature

    PR-URL: #338
    Credit: @push1st1k
    Close: #338
    Reviewed-by: @isaacs
    push1st1k authored and isaacs committed Jun 27, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    258b8ae View commit details
  2. ci: remove makework, update node versions

    isaacs committed Jun 27, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    200c622 View commit details
  3. fix few typos in README.md

    PR-URL: #337
    Credit: @zabdalimov
    Close: #337
    Reviewed-by: @isaacs
    zabdalimov authored and isaacs committed Jun 27, 2024
    Copy the full SHA
    a7868fc View commit details
  4. ttl docs fix

    fix: #316
    isaacs committed Jun 27, 2024
    Copy the full SHA
    aaaa7d7 View commit details
  5. add cache.forceFetch, a fetch() that cannot return undefined

    Fix: #329
    isaacs committed Jun 27, 2024
    Copy the full SHA
    01b4c0c View commit details
  6. Copy the full SHA
    cf8076e View commit details
  7. changelog 10.3

    isaacs committed Jun 27, 2024
    Copy the full SHA
    b421c41 View commit details

Commits on Jun 28, 2024

  1. add cache.memo(), options.memoMethod

    Fix: #335
    isaacs committed Jun 28, 2024
    Copy the full SHA
    40126dd View commit details
  2. changelog memo() method

    isaacs committed Jun 28, 2024
    Copy the full SHA
    4352239 View commit details
  3. docs: move all API and options docs into typedocs

    Things getting super out of sync being in two places.
    isaacs committed Jun 28, 2024
    Copy the full SHA
    bad77b9 View commit details
  4. 10.3.0

    isaacs committed Jun 28, 2024
    Copy the full SHA
    d71af85 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
node-version: [16.x, 18.x, 19.x]
node-version: [18.x, 20.x, 22.x]
platform:
- os: ubuntu-latest
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
node-version: [18.x, 20.x, 21.x]
node-version: [18.x, 20.x, 22.x]
platform:
- os: ubuntu-latest
shell: bash
13 changes: 0 additions & 13 deletions .github/workflows/commit-if-modified.sh

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/copyright-year.sh

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/isaacs-makework.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/package-json-repo.js

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# cringe lorg

## 10.3.0

- add `forceFetch()` method
- set `disposeReason` to `'expire'` when it's the result of a TTL
expiration, or `'fetch'` when it's the result of an aborted
or `undefined`-returning `fetch()`
- add `memo()` method

## 10.2.0

- types: implement the `Map<K, V>` interface
895 changes: 11 additions & 884 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lru-cache",
"description": "A cache object that deletes the least-recently-used items.",
"version": "10.2.2",
"version": "10.3.0",
"author": "Isaac Z. Schlueter <i@izs.me>",
"keywords": [
"mru",
715 changes: 634 additions & 81 deletions src/index.ts

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions test/dispose.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Clock } from 'clock-mock'
import t from 'tap'
import { LRUCache as LRU } from '../dist/esm/index.js'
import { LRUCache } from '../src/index.js'

t.test('disposal', t => {
const disposed: any[] = []
@@ -205,3 +207,53 @@ t.test('disposeAfter', t => {

t.end()
})

t.test('expiration reflected in dispose reason', async t => {
const clock = new Clock()
t.teardown(clock.enter())
clock.advance(1)
const disposes: [number, number, LRUCache.DisposeReason][] = []
const c = new LRUCache<number, number>({
ttl: 100,
max: 5,
dispose: (v, k, r) => disposes.push([k, v, r]),
})
c.set(1, 1)
c.set(2, 2, { ttl: 10 })
c.set(3, 3)
c.set(4, 4)
c.set(5, 5)
t.strictSame(disposes, [])
c.set(6, 6)
t.strictSame(disposes, [[1, 1, 'evict']])
c.delete(6)
c.delete(5)
c.delete(4)
// test when it's the last one, and when it's not, because we
// delete with cache.clear() when it's the only entry.
t.strictSame(disposes, [
[1, 1, 'evict'],
[6, 6, 'delete'],
[5, 5, 'delete'],
[4, 4, 'delete'],
])
clock.advance(20)
t.equal(c.get(2), undefined)
t.strictSame(disposes, [
[1, 1, 'evict'],
[6, 6, 'delete'],
[5, 5, 'delete'],
[4, 4, 'delete'],
[2, 2, 'expire'],
])
clock.advance(200)
t.equal(c.get(3), undefined)
t.strictSame(disposes, [
[1, 1, 'evict'],
[6, 6, 'delete'],
[5, 5, 'delete'],
[4, 4, 'delete'],
[2, 2, 'expire'],
[3, 3, 'expire'],
])
})
5 changes: 4 additions & 1 deletion test/fetch.ts
Original file line number Diff line number Diff line change
@@ -673,7 +673,7 @@ t.test('abort, but then keep on fetching anyway', async t => {
t.equal(ac.signal.reason, er)
t.equal(cache.get(1), 1)

const p2 = cache.fetch(2)
const p2 = cache.forceFetch(2)
t.equal(cache.get(2), undefined)
cache.delete(2)
t.equal(cache.get(2), undefined)
@@ -696,6 +696,9 @@ t.test('abort, but then keep on fetching anyway', async t => {
const p4 = cache.fetch(4)
clock.advance(100)
t.equal(await p4, undefined)
const p5 = cache.forceFetch(4)
clock.advance(100)
await t.rejects(p5, { message: 'fetch() returned undefined' })
t.same(e.valList, before, 'did not update values with undefined')
})