Skip to content

Return Resident struct from iter and iter_mut#116

Open
DenizUgur wants to merge 2 commits into
arthurprs:masterfrom
DenizUgur:return-resident-from-iter
Open

Return Resident struct from iter and iter_mut#116
DenizUgur wants to merge 2 commits into
arthurprs:masterfrom
DenizUgur:return-resident-from-iter

Conversation

@DenizUgur
Copy link
Copy Markdown

@DenizUgur DenizUgur commented May 7, 2026

This would help with #115 indirectly as I could insert to cache twice if ResidentState is Hot. I could then easily save and restore the cache. I would lose Ghost queue but at least residents would be restored.

This also helps if I need to now what hot items are in my cache if I need to perform some extra operation on them.

Edit: Upon further examining of the code I see the following logic, so if I were to iterate in reverse I would recreate the same cache anyway. My other point about knowing which item is hot or not is still a valid use case though.

quick-cache/src/shard.rs

Lines 1085 to 1095 in 8b0077f

let enter_hot = self.weight_hot + weight <= self.weight_target_hot;
// pre-evict instead of post-evict, this gives sightly more priority to the new item
while self.weight_hot + self.weight_cold + weight > self.weight_capacity
&& self.advance_cold(lcs)
{}
let (state, list_head) = if enter_hot {
self.num_hot += 1;
self.weight_hot += weight;
(ResidentState::Hot, &mut self.hot_head)
} else {

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.

1 participant