golang-lru icon indicating copy to clipboard operation
golang-lru copied to clipboard

Enable iteration of key/val pairs in expirable LRU

Open bhperry opened this issue 1 year ago • 3 comments

There is currently no way to iterate over key/val pairs in the cache. Can't combine the outputs of Keys() and Values() since new entries could have been added or old entries expire between the two calls. Only other option would be to call Keys() and Peek(...) every key, but that is not very efficient.

Given that the K/V Entries struct is internal only, I propose adding a Range(...) function that will call a function on each K/V pair in the cache. This way the lock only needs to be acquired once to make a list of current unexpired entries (similar to how the Keys() and Values() functions work), and then the callback is free to make modifications to the cache as it iterates.

bhperry avatar May 28 '24 14:05 bhperry

CLA assistant check
All committers have signed the CLA.

hashicorp-cla-app[bot] avatar May 28 '24 14:05 hashicorp-cla-app[bot]

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

hashicorp-cla-app[bot] avatar May 28 '24 14:05 hashicorp-cla-app[bot]

I was looking for something like this. Seems like project is not maintained no reviewrs/approvers ?

rajatkb avatar Dec 14 '24 06:12 rajatkb