go-generics-cache
go-generics-cache copied to clipboard
Len() method missing from common cache interface
It would be useful to have Len() method available in common interface. I would need it for getting metrics for cache usage.
It is available if the cache is created with exact policy lru.NewCache()
but if you want to use context cache.NewContext()
then common interface is returned. len(c.Keys())
could be used but it's still not the same.
Example:
ctx := context.Background()
var myCache *cache.Cache[string, int]
myCache = cache.NewContext(ctx, cache.AsLRU[string, int](lru.WithCapacity(10)))
// myCache is LRU cache but myCache.Len() is not available
@norri Hi 👋 I'm not sure what do you mean this?
len(c.Keys()) could be used but it's still not the same.
I thought this meant len(c.Keys()) != c.Len() right?
The result is the same. I just thought that there is no need to go through all the keys to get the lenght. Nevermind this my comment.
@norri I commented your PR. If you don't kneed the changes, please close PR and this issues 🙏
I still need this. Added new comments to PR.