isaacs / node-lru-cache

A fast cache that automatically deletes the least recently used items
http://isaacs.github.io/node-lru-cache/
ISC License
5.38k stars 353 forks source link

Add "find" function #182

Closed telion2 closed 2 years ago

telion2 commented 3 years ago

Hi, I currently have a use-case where I need to find a value in the lru-cache without a key.

simple example: key: 111, { someId: 111, name: "whatImLookingFor"}

Currently I have to do something like:

lru.values().find(el => el.name === "whatImLookingFor")

However, this will not update the "recently used"-ness. (or will it?)

I am sure there is a way to update that, but I think its easier for all to add it to lru-Cache, as I expect it to be quite common, that one wants to find an element not based on the key.

isaacs commented 2 years ago

This is easy to add in v7, so I'll add it in v7.