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

Add API to explicitly control LRUness of keys #152

Merged
merged 1 commit into from Sep 11, 2022

Conversation

matklad
Copy link
Contributor

@matklad matklad commented Aug 22, 2022

promote is mostly just get. demote is new, and wasn't expressible
before: it allows the caller to hint that the value likely won't be used
in the future.

The context I need this is near/nearcore#7429. Basically, we have a functional (persistent, versioned) tree stored in the database, and we have an lru in-memory cache of nodes on top of it. The most recent version of the tree is what's accessed most of the times, but historical versions are occasionally accessed as well. So, when we "remove" a node from a tree, we want to mark the cached version as a likely candidate for eviction, but we don't quite want to delete it outright, as it still might be useful if someone looks at the previous version.

If you are generally onboard with the API, I'll work on proper doc comments, tests, and making sure I don't mess up linked list manipulation :)

Open to suggestion on the naming: promote/demote work OK, but not quite perfect. touch would be ideal for promote, but it doesn't have a catchy antonym it seems.

@jeromefroe
Copy link
Owner

@matklad this looks great! Once you finish the polishing you had in mind I think we should be good to merge.

`promote` is mostly just `get`. `demote` is new, and wasn't expressible
before: it allows the caller to hint that the value likely won't be used
in the future.
@matklad matklad changed the title WIP: add API to explicitly control LRUness of keys Add API to explicitly control LRUness of keys Sep 6, 2022
@matklad
Copy link
Contributor Author

matklad commented Sep 6, 2022

@jeromefroe PTAL!

@jeromefroe
Copy link
Owner

Looks great, thanks @matklad!

@jeromefroe jeromefroe merged commit 29561cb into jeromefroe:master Sep 11, 2022
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 this pull request may close these issues.

None yet

2 participants