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

List currently stored items #10

Open
dignifiedquire opened this issue Jan 4, 2017 · 8 comments
Open

List currently stored items #10

dignifiedquire opened this issue Jan 4, 2017 · 8 comments

Comments

@dignifiedquire
Copy link

Due to the way it is currently implemented there is no way to get a list of all currently stored items. It would be nice this was exposed somehow.

@dominictarr
Copy link
Owner

can you describe your use-case? is this just for testing or is it part of your application?

@dignifiedquire
Copy link
Author

It's part of the application. I'm using the lru cache to store records that can expire, and I need to iterate through all of the ones I still have around every time period and delete them if they are expired.

@dominictarr
Copy link
Owner

right! so actually you need expiring keys not iteration! a more traditional LRU (with linked list) can support that. (I know lru-cache has that) to apply the hashlru approach, you could just force a cycle of the caches every period.

Do things need different expiry times? why do things need to expire after a time? why can't they just stay in the cache?

@dominictarr
Copy link
Owner

since a typical LRU has a linked list (in the order of most recently added) it can expire keys after a time efficiently (because it can iterate over only the tail oldest elements in the list) if you are iterating over the entire cache to expire keys, that in O(N) every time.

does it matter if something happens to stay in the cache a bit after it's expiry?

@dignifiedquire
Copy link
Author

They are dht provider records. Each cache item is a list of providers with a timestamp when they were last seen. So I iterate through all of that and drop the items inside of that map and only if all of the providers are dropped I remove the whole entry from the cache.
So the regular lru cache doesn't fully solve what I want to do either, as I need to actually look into every item.

@dignifiedquire
Copy link
Author

The default time of checks is once an hour, so it's not a big problem if it isn't super fast.

@davidmarkclements
Copy link
Collaborator

davidmarkclements commented Jan 4, 2017

@dignifiedquire I guess we need to decide if hashlru is right for you, does/should the scope cater to your case (nested cache) - I'm leaning towards no...

@dominictarr
Copy link
Owner

hmm, so the providers are the peers which also share a given item? and a provider may share many different things, so you want to remove all of them from the cache after the time.

one thing you could do, is just remove expired providers when you read from the cache.

but I guess we could add this feature, as long as there is clear documentation that it is not part of the optimized api.

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

No branches or pull requests

3 participants