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

Len() method missing from common cache interface #43

Closed
norri opened this issue Jun 9, 2023 · 4 comments · Fixed by #44
Closed

Len() method missing from common cache interface #43

norri opened this issue Jun 9, 2023 · 4 comments · Fixed by #44

Comments

@norri
Copy link

norri commented Jun 9, 2023

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 norri changed the title Len missing from common cache interface Len() method missing from common cache interface Jun 9, 2023
@Code-Hex
Copy link
Owner

Code-Hex commented Jun 9, 2023

@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?

@norri
Copy link
Author

norri commented Jun 9, 2023

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.

@Code-Hex
Copy link
Owner

@norri I commented your PR.
If you don't kneed the changes, please close PR and this issues 🙏

@norri
Copy link
Author

norri commented Jun 12, 2023

I still need this. Added new comments to PR.

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

Successfully merging a pull request may close this issue.

2 participants