pub struct AdaptiveCachePolicy { /* private fields */ }Expand description
Read-only policy object that reads ResourceGuard::pressure() and produces
cache directives. Does not own any cache — it only tells other code what
to do.
Use AdaptiveCachePolicy::new_with_guard when sharing a ResourceGuard with a builder or
other subsystem (recommended). Use AdaptiveCachePolicy::new when the cache policy needs its
own independent ceiling.
Implementations§
Source§impl AdaptiveCachePolicy
impl AdaptiveCachePolicy
Sourcepub fn new(ceiling_fraction: f64) -> Self
pub fn new(ceiling_fraction: f64) -> Self
Creates a new policy with the given ceiling fraction of system memory.
For example, 0.6 means use 60 % of system memory as the ceiling.
Internally delegates to ResourceGuard::auto(ceiling_fraction).
Sourcepub fn new_with_guard(guard: ResourceGuard, ceiling_bytes: usize) -> Self
pub fn new_with_guard(guard: ResourceGuard, ceiling_bytes: usize) -> Self
Creates a policy sharing an existing ResourceGuard.
This is the recommended constructor for daemons: one guard governs both the builder’s safety checks AND the cache’s pressure readings, so they never disagree about how much memory is available.
ceiling_bytes must match the guard’s internal ceiling
(i.e., the value passed to ResourceGuard::new or computed by auto).
Sourcepub fn guard(&self) -> &ResourceGuard
pub fn guard(&self) -> &ResourceGuard
Returns a reference to the underlying ResourceGuard.
Sourcepub fn directive(&self) -> CacheDirective
pub fn directive(&self) -> CacheDirective
Returns a CacheDirective reflecting the current memory pressure.
⚠ BLOCKING: This call internally invokes ResourceGuard::pressure()
which reads /proc/stat twice with a 100 ms sleep between reads on Linux
(via raw_entropy() / delta_iowait_ratio()). Do not call this in
an async context without spawn_blocking.
§Zone mapping
| Zone | Pressure | evict_fraction | allow_new_entries | allow_mmap_pin |
|---|---|---|---|---|
| Green | 0–40 | 0.0 | true | true |
| Yellow | 41–70 | 0.1 | true | true |
| Orange | 71–90 | 0.5 | false | false |
| Red | 91–100 | 1.0 | false | false |
Sourcepub fn pressure(&self) -> u8
pub fn pressure(&self) -> u8
Convenience wrapper for ResourceGuard::pressure().
⚠ BLOCKING: See directive for blocking details.
Sourcepub fn ceiling_bytes(&self) -> usize
pub fn ceiling_bytes(&self) -> usize
Returns the memory ceiling in bytes that this policy is configured with.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AdaptiveCachePolicy
impl RefUnwindSafe for AdaptiveCachePolicy
impl Send for AdaptiveCachePolicy
impl Sync for AdaptiveCachePolicy
impl Unpin for AdaptiveCachePolicy
impl UnsafeUnpin for AdaptiveCachePolicy
impl UnwindSafe for AdaptiveCachePolicy
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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