Add API to explicitly control LRUness of keys #152
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
promote
is mostly justget
.demote
is new, and wasn't expressiblebefore: 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 forpromote
, but it doesn't have a catchy antonym it seems.