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
impl AdaptivePolicy
Sourcepub fn new(config: AdaptiveConfig) -> Result<AdaptivePolicy, AdaptiveError>
pub fn new(config: AdaptiveConfig) -> Result<AdaptivePolicy, AdaptiveError>
Create a new policy from the given configuration.
Returns an error if the configuration is invalid.
Sourcepub fn with_initial_capacity(
config: AdaptiveConfig,
initial_capacity: usize,
) -> Result<AdaptivePolicy, AdaptiveError>
pub fn with_initial_capacity( config: AdaptiveConfig, initial_capacity: usize, ) -> Result<AdaptivePolicy, AdaptiveError>
Create a policy with a specific initial capacity.
Sourcepub fn record_hit(&mut self) -> Option<Adjustment>
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.
Sourcepub fn record_miss(&mut self) -> Option<Adjustment>
pub fn record_miss(&mut self) -> Option<Adjustment>
Record a cache miss.
Returns Some(Adjustment) when this observation triggers an
evaluation, None otherwise.
Sourcepub fn evaluate_now(&mut self) -> Adjustment
pub fn evaluate_now(&mut self) -> Adjustment
Force an evaluation regardless of the operation counter.
Sourcepub fn rolling_hit_rate(&self) -> f64
pub fn rolling_hit_rate(&self) -> f64
Current rolling hit rate.
Sourcepub fn total_hits(&self) -> u64
pub fn total_hits(&self) -> u64
Total hits since creation / last reset.
Sourcepub fn total_misses(&self) -> u64
pub fn total_misses(&self) -> u64
Total misses since creation / last reset.
Sourcepub fn lifetime_hit_rate(&self) -> f64
pub fn lifetime_hit_rate(&self) -> f64
Lifetime hit rate (not rolling-windowed).
Sourcepub fn current_capacity(&self) -> usize
pub fn current_capacity(&self) -> usize
Currently recommended capacity.
Sourcepub fn adjustments_made(&self) -> u64
pub fn adjustments_made(&self) -> u64
Number of adjustments made so far.
Sourcepub fn history(&self) -> &[AdjustmentRecord]
pub fn history(&self) -> &[AdjustmentRecord]
Read-only access to the adjustment history.
Sourcepub fn config(&self) -> &AdaptiveConfig
pub fn config(&self) -> &AdaptiveConfig
The active configuration.
Sourcepub fn window_fill(&self) -> usize
pub fn window_fill(&self) -> usize
Total number of observations in the rolling window.