Skip to main content

AdaptivePolicy

Struct AdaptivePolicy 

Source
pub struct AdaptivePolicy { /* private fields */ }
Expand description

Adaptive cache threshold policy.

Tracks rolling hit/miss observations and periodically evaluates whether the cache should grow or shrink. The policy itself does not mutate any cache; it produces Adjustment recommendations.

Implementations§

Source§

impl AdaptivePolicy

Source

pub fn new(config: AdaptiveConfig) -> Result<AdaptivePolicy, AdaptiveError>

Create a new policy from the given configuration.

Returns an error if the configuration is invalid.

Source

pub fn with_initial_capacity( config: AdaptiveConfig, initial_capacity: usize, ) -> Result<AdaptivePolicy, AdaptiveError>

Create a policy with a specific initial capacity.

Source

pub fn record_hit(&mut self) -> Option<Adjustment>

Record a cache hit.

Returns Some(Adjustment) when this observation triggers an evaluation (every adjustment_interval operations), None otherwise.

Source

pub fn record_miss(&mut self) -> Option<Adjustment>

Record a cache miss.

Returns Some(Adjustment) when this observation triggers an evaluation, None otherwise.

Source

pub fn evaluate_now(&mut self) -> Adjustment

Force an evaluation regardless of the operation counter.

Source

pub fn rolling_hit_rate(&self) -> f64

Current rolling hit rate.

Source

pub fn total_hits(&self) -> u64

Total hits since creation / last reset.

Source

pub fn total_misses(&self) -> u64

Total misses since creation / last reset.

Source

pub fn lifetime_hit_rate(&self) -> f64

Lifetime hit rate (not rolling-windowed).

Source

pub fn current_capacity(&self) -> usize

Currently recommended capacity.

Source

pub fn adjustments_made(&self) -> u64

Number of adjustments made so far.

Source

pub fn history(&self) -> &[AdjustmentRecord]

Read-only access to the adjustment history.

Source

pub fn config(&self) -> &AdaptiveConfig

The active configuration.

Source

pub fn window_fill(&self) -> usize

Total number of observations in the rolling window.

Source

pub fn reset(&mut self)

Reset all counters and the rolling window, keeping the current configuration.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.