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

Fix clone when the stats feature is enabled #51

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ enum Entry<Key, Val, Plh> {
/// A bounded cache using a modified CLOCK-PRO eviction policy.
/// The implementation allows some parallelism as gets don't require exclusive access.
/// Any evicted items are returned so they can be dropped by the caller, outside the locks.
#[derive(Clone)]
pub struct CacheShard<Key, Val, We, B, L, Plh> {
hash_builder: B,
/// Map to an entry in the `entries` slab.
Expand Down Expand Up @@ -102,6 +101,35 @@ pub struct CacheShard<Key, Val, We, B, L, Plh> {
pub(crate) lifecycle: L,
}

impl<Key: Clone, Val: Clone, We: Clone, B: Clone, L: Clone, Plh: Clone> Clone
for CacheShard<Key, Val, We, B, L, Plh>
{
fn clone(&self) -> Self {
Self {
hash_builder: self.hash_builder.clone(),
map: self.map.clone(),
entries: self.entries.clone(),
cold_head: self.cold_head,
hot_head: self.hot_head,
ghost_head: self.ghost_head,
weight_target_hot: self.weight_target_hot,
weight_capacity: self.weight_capacity,
weight_hot: self.weight_hot,
weight_cold: self.weight_cold,
num_hot: self.num_hot,
num_cold: self.num_cold,
num_non_resident: self.num_non_resident,
capacity_non_resident: self.capacity_non_resident,
#[cfg(feature = "stats")]
hits: self.hits.load(atomic::Ordering::Relaxed).into(),
#[cfg(feature = "stats")]
misses: self.misses.load(atomic::Ordering::Relaxed).into(),
weighter: self.weighter.clone(),
lifecycle: self.lifecycle.clone(),
}
}
}

#[cfg(feature = "stats")]
macro_rules! record_hit {
($self: expr) => {{
Expand Down
Loading