Repository navigation
Dedicated method with state as an input - #5
Merged
Merged
Conversation
dispanser
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
insert_with_stateandtry_insert_with_state— variants of the existing_with_lifecyclemethods that accept a caller-owned&mut L::RequestStateinstead of creating one internally. The existing_with_lifecyclemethods are refactored to delegate to these, eliminating duplicated shard-lookup and insert logic.Motivation
The
_with_lifecyclemethods give callers control over when evicted items are dropped (outside the shard lock). However, they each create their own lifecycle request, so callers who need to batch multiple insertions under a singlebegin_request/end_requestpair had no supported way to do so.The new
_with_statemethods fill this gap:Changes
insert_with_state(&self, key, value, lcs: &mut L::RequestState)— blocking insert into an existing lifecycle request.try_insert_with_state(&self, key, value, lcs: &mut L::RequestState) -> Result<(), (Key, Val)>— non-blocking variant; returns inputs on lock contention.insert_with_lifecycleandtry_insert_with_lifecyclenow delegate to the new methods.with_weighter,replace_with_lifecycle,insert_with_lifecycle,get_or_insert_with, andget_or_insert_async.