pub trait Eviction:
Send
+ Sync
+ 'static
+ Sized {
type Config: Config;
type Key: Key;
type Value: Value;
type Properties: Properties;
type State: State;
// Required methods
fn new(capacity: usize, config: &Self::Config) -> Self;
fn update(
&mut self,
capacity: usize,
config: Option<&Self::Config>,
) -> Result<()>;
fn push(&mut self, record: Arc<Record<Self>>);
fn pop(&mut self) -> Option<Arc<Record<Self>>>;
fn remove(&mut self, record: &Arc<Record<Self>>);
fn acquire() -> Op<Self>;
fn release() -> Op<Self>;
// Provided method
fn clear(&mut self) { ... }
}Expand description
Cache eviction algorithm abstraction.
Eviction provides essential APIs for the plug-and-play algorithm abstraction.
Eviction is needs to be implemented to support a new cache eviction algorithm.
§Safety
The pointer can be dereferenced as a mutable reference iff the self reference is also mutable.
Dereferencing a pointer as a mutable reference when self is immutable will cause UB.
Required Associated Types§
Sourcetype Value: Value
type Value: Value
Cache value. Generally, it is supposed to be a generic type of the implementation.
Sourcetype Properties: Properties
type Properties: Properties
Properties for a cache entry, it is supposed to be a generic type of the implementation.
Can be used to support priority at the entry granularity.
Required Methods§
Sourcefn new(capacity: usize, config: &Self::Config) -> Self
fn new(capacity: usize, config: &Self::Config) -> Self
Create a new cache eviction algorithm instance with the given arguments.
Sourcefn update(
&mut self,
capacity: usize,
config: Option<&Self::Config>,
) -> Result<()>
fn update( &mut self, capacity: usize, config: Option<&Self::Config>, ) -> Result<()>
Update the arguments of the ache eviction algorithm instance.
Sourcefn push(&mut self, record: Arc<Record<Self>>)
fn push(&mut self, record: Arc<Record<Self>>)
Push a record into the cache eviction algorithm instance.
The caller guarantees that the record is NOT in the cache eviction algorithm instance.
The cache eviction algorithm instance MUST hold the record and set its IN_EVICTION flag to true.
Sourcefn pop(&mut self) -> Option<Arc<Record<Self>>>
fn pop(&mut self) -> Option<Arc<Record<Self>>>
Push a record from the cache eviction algorithm instance.
The cache eviction algorithm instance MUST remove the record and set its IN_EVICTION flag to false.
Sourcefn remove(&mut self, record: &Arc<Record<Self>>)
fn remove(&mut self, record: &Arc<Record<Self>>)
Remove a record from the cache eviction algorithm instance.
The caller guarantees that the record is in the cache eviction algorithm instance.
The cache eviction algorithm instance MUST remove the record and set its IN_EVICTION flag to false.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.