pub struct MetadataCachePolicy { /* private fields */ }Expand description
Every caching decision, in one place. Given an info’s size and the current
CacheMode, the policy decides whether that info is cached at all
(should_cache) and, through its
capacity, when the cache must evict to stay bounded. How
those decisions are carried out (lookups, eviction) is the cache’s job and
differs per runtime; what to do lives here.
max_entries and max_cached_size are the backend-tunable knobs.
Implementations§
Source§impl MetadataCachePolicy
impl MetadataCachePolicy
Sourcepub fn new(max_entries: usize, max_cached_size: usize) -> Self
pub fn new(max_entries: usize, max_cached_size: usize) -> Self
Build a policy in CacheMode::Normal. max_entries caps the number of
cached entries; max_cached_size (bytes) is the largest info still worth
caching in normal operation.
Sourcepub fn mode(&mut self, mode: CacheMode)
pub fn mode(&mut self, mode: CacheMode)
Switch the mode driving the policy’s decisions (see CacheMode).
Sourcepub fn should_cache(&self, size: usize) -> bool
pub fn should_cache(&self, size: usize) -> bool
Whether an info of size bytes should go through the cache at all. In
CacheMode::Normal a too-large info (or a disabled cache) is skipped:
the runtime should create it directly, without a lookup or a store. In
CacheMode::Capture everything is cached so the capture window stays
warm.
Sourcepub fn capacity(&self) -> Option<usize>
pub fn capacity(&self) -> Option<usize>
The entry bound the cache must hold to, or None when unbounded. In
CacheMode::Capture the cache is unbounded and never evicts (dropping
an entry could free a buffer a recorded launch still needs); in
CacheMode::Normal it is capped at max_entries.
Sourcepub fn pins_entries(&self) -> bool
pub fn pins_entries(&self) -> bool
Whether entries touched right now must be pinned to the graph being
captured. True in CacheMode::Capture: a graph records the device
pointer of every info buffer its launches touch, so those entries must
not be evicted for the graph’s lifetime — even after the cache returns to
CacheMode::Normal, and even if the buffer lives in the regular
(non-persistent) pool and so is not otherwise retained by the graph.
Trait Implementations§
Source§impl Clone for MetadataCachePolicy
impl Clone for MetadataCachePolicy
Source§fn clone(&self) -> MetadataCachePolicy
fn clone(&self) -> MetadataCachePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for MetadataCachePolicy
Source§impl Debug for MetadataCachePolicy
impl Debug for MetadataCachePolicy
Auto Trait Implementations§
impl Freeze for MetadataCachePolicy
impl RefUnwindSafe for MetadataCachePolicy
impl Send for MetadataCachePolicy
impl Sync for MetadataCachePolicy
impl Unpin for MetadataCachePolicy
impl UnsafeUnpin for MetadataCachePolicy
impl UnwindSafe for MetadataCachePolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more