Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserted items are evicted immediately if no maxSize is set #257

Closed
dkaps125 opened this issue Nov 2, 2022 · 4 comments
Closed

Inserted items are evicted immediately if no maxSize is set #257

dkaps125 opened this issue Nov 2, 2022 · 4 comments

Comments

@dkaps125
Copy link
Contributor

dkaps125 commented Nov 2, 2022

I'm not sure if this is intended, but it's definitely bizarre behavior given that this parameter is optional. See the following example:

const cache = LRU({
  max: 500,
  maxEntrySize: 75,
  sizeCalculation: (_value, key) => key.length,
  fetchMethod(key) {
    return `${Math.random()}`
  }
});

console.log(await cache.fetch('test')); // prints a random decimal
console.log(await cache.has('test')); // prints false

I think this while loop should only be run when maxSize is defined, and maxSize shouldn't default to 0.

@isaacs
Copy link
Owner

isaacs commented Nov 2, 2022 via email

@dkaps125
Copy link
Contributor Author

dkaps125 commented Nov 2, 2022

@isaacs thanks for confirming. I'll put up a PR to address in the next day or so.

dkaps125 added a commit to dkaps125/node-lru-cache that referenced this issue Nov 2, 2022
@isaacs isaacs closed this as completed in ff254a7 Nov 2, 2022
@isaacs
Copy link
Owner

isaacs commented Nov 2, 2022

Thanks, fixed on 7.14.1 (took your commit, added a test and fixed a weird interaction with this and async fetching, where it was trying to calculate the length of background fetch promises).

@isaacs isaacs closed this as completed Nov 2, 2022
@dkaps125
Copy link
Contributor Author

dkaps125 commented Nov 2, 2022

Awesome, thanks for closing this out so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants