pub trait Resizable: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn current_bytes(&self) -> u64;
fn max_bytes(&self) -> u64;
fn set_max_bytes(&self, new: u64);
fn stats(&self) -> ResizableStats;
}Expand description
Minimal interface a memory-budget-aware cache must expose.
All methods are &self because caches use interior mutability (a
Mutex<LruCache<...>> or a moka::sync::Cache). The budget holds
Weak<dyn Resizable> handles so a dropped cache is silently
removed from the next tick.
Required Methods§
Sourcefn current_bytes(&self) -> u64
fn current_bytes(&self) -> u64
Current bytes held by the cache.
Sourcefn max_bytes(&self) -> u64
fn max_bytes(&self) -> u64
Configured soft cap. Honoured eagerly (eviction-on-insert) and
at each tick by Resizable::set_max_bytes.
Sourcefn set_max_bytes(&self, new: u64)
fn set_max_bytes(&self, new: u64)
Update the soft cap. The cache may either evict synchronously
(small caches) or schedule eviction over the next few ops
(large caches). Either is acceptable as long as
Resizable::current_bytes converges to new within one
budget tick.
Sourcefn stats(&self) -> ResizableStats
fn stats(&self) -> ResizableStats
Stats sample used by the reapportionment policy.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".