LruTimestamp

Trait LruTimestamp 

Source
pub trait LruTimestamp {
    type Timestamp<'a>: PartialOrd
       where Self: 'a;

    // Required methods
    fn get_timestamp(&self) -> Self::Timestamp<'_>;
    fn update_timestamp(&self);
}
Expand description

A trait for anything that has a timestamp that we can use with an LRU cache replacement policy.

Don’t already have a timestamp in your cache value? Consider using the WithLruTimestamp<T> wrapper type around your cache value. That is likely a little easier than implementing this trait yourself.

Required Associated Types§

Source

type Timestamp<'a>: PartialOrd where Self: 'a

The timestamp type that will be compared.

The entry with smallest timestamp value (according to its PartialOrd implementation) is the one that will be replaced.

Required Methods§

Source

fn get_timestamp(&self) -> Self::Timestamp<'_>

Get this cache value’s timestamp.

Source

fn update_timestamp(&self)

Update this cache value’s timestamp.

Note that this takes &self, not &mut self, because this is called on all cache hits, where we don’t necessarily have &mut access to the cache. It is up to implementors to use internal mutability to update the timestamp.

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§

Source§

impl<T> LruTimestamp for WithLruTimestamp<T>

Source§

type Timestamp<'a> = &'a Cell<Instant> where T: 'a