-
Notifications
You must be signed in to change notification settings - Fork 27
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
Comments
can you describe your use-case? is this just for testing or is it part of your application? |
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. |
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? |
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? |
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. |
The default time of checks is once an hour, so it's not a big problem if it isn't super fast. |
@dignifiedquire I guess we need to decide if |
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. |
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.
The text was updated successfully, but these errors were encountered: