Proposal: add metrics KeysNumber

Moved from GitHub ristretto/135

Posted by choleraehyq:

Here I want to get the key numbers current cache contains. Seems it’s easy to maintain.


martinmr commented :

Just to make sure we are on the same page you want Ristretto to report the current number of key-value pairs stored in the cache.

This would be easy to code but it’s not as straight-forward as the other metrics because Ristretto uses a sharded map so we’d need to iterate through the maps (while holding the locks for each shard) so there are performance implications. All the other metrics are reported via atomic counters which means there’s no locking involved.

I’ll bring it up to @manishrjain to see what he thinks.

blasrodri commented :

@martinmr would it be possible to store an atomic integer that reflects this number, and gets updated every time a key is added/evicted?

Is this proposal planned for an upcoming release? This thread has been here for more than a year.
Is there any current way or work-around to get the cache keys number?