-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Entry Snapshot — Rename the
cache.policy_snapshot()
method to
`cache.policy_ext().entry_snapshot()`. Also remove the `estimated_frequency` field from the `EntryMetadata` struct.
- Loading branch information
1 parent
5c0caaf
commit acfdd8b
Showing
9 changed files
with
233 additions
and
187 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::{ | ||
common::deque::DeqNode, | ||
policy::{EntrySnapshot, EntrySnapshotConfig, ExpirationPolicy}, | ||
}; | ||
|
||
use super::{ | ||
concurrent::{deques::Deques, KeyHashDateNodePtr}, | ||
entry::EntryMetadata, | ||
time::Clock, | ||
}; | ||
|
||
impl<K, V> ExpirationPolicy<K, V> { | ||
pub(crate) fn capture_entry_snapshot( | ||
&self, | ||
sc: EntrySnapshotConfig, | ||
deqs: &Deques<K>, | ||
clock: &Clock, | ||
) -> EntrySnapshot<K> { | ||
use crate::entry::EntryRegion; | ||
|
||
let coldest_entries = if sc.coldest == 0 { | ||
Vec::new() | ||
} else { | ||
self.top_entries( | ||
EntryRegion::Main, | ||
sc.coldest, | ||
deqs.probation.peek_front_ptr(), | ||
DeqNode::next_node_ptr, | ||
clock, | ||
) | ||
}; | ||
|
||
let hottest_entries = if sc.hottest == 0 { | ||
Vec::new() | ||
} else { | ||
self.top_entries( | ||
EntryRegion::Main, | ||
sc.hottest, | ||
deqs.probation.peek_back_ptr(), | ||
DeqNode::prev_node_ptr, | ||
clock, | ||
) | ||
}; | ||
|
||
EntrySnapshot::new(coldest_entries, hottest_entries) | ||
} | ||
|
||
fn top_entries( | ||
&self, | ||
region: crate::entry::EntryRegion, | ||
count: usize, | ||
head: Option<KeyHashDateNodePtr<K>>, | ||
next_fun: fn(KeyHashDateNodePtr<K>) -> Option<KeyHashDateNodePtr<K>>, | ||
clock: &Clock, | ||
) -> Vec<(Arc<K>, EntryMetadata)> { | ||
let mut entries = Vec::with_capacity(count); | ||
|
||
let mut next = head; | ||
while entries.len() < count { | ||
let Some(current) = next.take() else { | ||
break; | ||
}; | ||
next = next_fun(current); | ||
|
||
let elem = &unsafe { current.as_ref() }.element; | ||
if elem.is_dirty() { | ||
continue; | ||
} | ||
|
||
let snapshot_at = clock.to_std_instant(clock.now()); | ||
let md = EntryMetadata::from_element( | ||
region, | ||
elem, | ||
clock, | ||
self.time_to_live(), | ||
self.time_to_idle(), | ||
snapshot_at, | ||
); | ||
entries.push((Arc::clone(elem.key()), md)); | ||
} | ||
|
||
entries | ||
} | ||
} |
Oops, something went wrong.