pub struct KvCachePolicy { /* private fields */ }Expand description
Stateful KV-cache compression policy.
Thread-safe: the current level is stored in an AtomicU8 so concurrent
observers can read without locking. The pressure EWMA is also stored
atomically (as u64-encoded f64 bits).
Implementations§
Source§impl KvCachePolicy
impl KvCachePolicy
Sourcepub fn new(config: KvCachePolicyConfig) -> Result<Self, KvCachePolicyError>
pub fn new(config: KvCachePolicyConfig) -> Result<Self, KvCachePolicyError>
Construct a new policy.
Returns an error if the config is invalid (out-of-range thresholds,
inverted hysteresis, or min_level > max_level).
Sourcepub fn current_level(&self) -> KvCacheLevel
pub fn current_level(&self) -> KvCacheLevel
Read the current level.
Sourcepub fn downgrades(&self) -> u64
pub fn downgrades(&self) -> u64
Number of downgrades fired since construction.
Sourcepub fn observe(&self, pressure: f64) -> KvCacheLevel
pub fn observe(&self, pressure: f64) -> KvCacheLevel
Record a new pressure observation and return the (possibly updated) active level.
pressure is expected in [0.0, 1.0]; values are clamped to that
range before being fed into the EWMA.
Sourcepub fn reset(&self)
pub fn reset(&self)
Reset the EWMA, sample counter, and tier to the configured minimum. Counters for upgrades/downgrades are also reset.
Sourcepub fn config(&self) -> &KvCachePolicyConfig
pub fn config(&self) -> &KvCachePolicyConfig
Return the configuration this policy was built with.
Trait Implementations§
Source§impl Debug for KvCachePolicy
impl Debug for KvCachePolicy
Auto Trait Implementations§
impl !Freeze for KvCachePolicy
impl RefUnwindSafe for KvCachePolicy
impl Send for KvCachePolicy
impl Sync for KvCachePolicy
impl Unpin for KvCachePolicy
impl UnsafeUnpin for KvCachePolicy
impl UnwindSafe for KvCachePolicy
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