Eviction

Trait Eviction 

Source
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§

Source

type Config: Config

Cache eviction algorithm configurations.

Source

type Key: Key

Cache key. Generally, it is supposed to be a generic type of the implementation.

Source

type Value: Value

Cache value. Generally, it is supposed to be a generic type of the implementation.

Source

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.

Source

type State: State

State for a cache entry. Mutable state for maintaining the cache eviction algorithm implementation.

Required Methods§

Source

fn new(capacity: usize, config: &Self::Config) -> Self

Create a new cache eviction algorithm instance with the given arguments.

Source

fn update( &mut self, capacity: usize, config: Option<&Self::Config>, ) -> Result<()>

Update the arguments of the ache eviction algorithm instance.

Source

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.

Source

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.

Source

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.

Source

fn acquire() -> Op<Self>

acquire is called when an external caller acquire a cache entry from the cache.

The entry can be EITHER in the cache eviction algorithm instance or not.

Source

fn release() -> Op<Self>

release is called when the last external caller drops the cache entry.

The entry can be EITHER in the cache eviction algorithm instance or not.

Provided Methods§

Source

fn clear(&mut self)

Remove all records from the cache eviction algorithm instance.

The cache eviction algorithm instance MUST remove the records and set its IN_EVICTION flag to false.

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.

Implementors§