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: v7.4.3
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: v7.4.4
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Mar 10, 2022

  1. fix: purgeStale lockup on list reordering

    Fix: ##209
    isaacs committed Mar 10, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    isaacs isaacs
    Copy the full SHA
    212804e View commit details
  2. 7.4.4

    isaacs committed Mar 10, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    isaacs isaacs
    Copy the full SHA
    aaf23ed View commit details
Showing with 25 additions and 4 deletions.
  1. +5 −1 index.js
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +17 −0 test/ttl.js
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -315,12 +315,16 @@ class LRUCache {

purgeStale () {
let deleted = false
const toDelete = []
for (const i of this.rindexes({ allowStale: true })) {
if (this.isStale(i)) {
this.delete(this.keyList[i])
toDelete.push(this.keyList[i])
deleted = true
}
}
for (const k of toDelete) {
this.delete(k)
}
return deleted
}

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,7 +1,7 @@
{
"name": "lru-cache",
"description": "A cache object that deletes the least-recently-used items.",
"version": "7.4.2",
"version": "7.4.4",
"author": "Isaac Z. Schlueter <i@izs.me>",
"keywords": [
"mru",
17 changes: 17 additions & 0 deletions test/ttl.js
Original file line number Diff line number Diff line change
@@ -359,6 +359,23 @@ const runTests = (LRU, t) => {
t.end()
})

t.test('purgeStale() lockup', t => {
const c = new LRU({
max: 3,
ttl: 10,
updateAgeOnGet: true,
})
c.set(1, 1)
c.set(2, 2)
c.set(3, 3)
clock.advance(5)
c.get(2)
clock.advance(15)
c.purgeStale()
t.pass('did not get locked up')
t.end()
})

t.end()
}