Skip to main content

Cache

Trait Cache 

Source
pub trait Cache: Send + Sync {
    // Required methods
    fn record_access<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
        hit: bool,
        size_bytes: Option<usize>,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn remove<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn contains<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_metrics<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = CacheMetrics> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn cleanup_expired<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Common cache trait for metadata tracking

This trait abstracts the cache interface, allowing different implementations (LRU, Adaptive TTL) to be used interchangeably in RedbStorage.

All implementations must be Send + Sync for thread-safe async access.

Required Methods§

Source

fn record_access<'life0, 'async_trait>( &'life0 self, id: Uuid, hit: bool, size_bytes: Option<usize>, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Record a cache access (hit or miss)

§Arguments
  • id - Unique identifier for the cache entry
  • hit - Whether this was a cache hit (true) or miss (false)
  • size_bytes - Optional size in bytes (for size-aware eviction)
§Returns

true if the entry was found and is valid, false otherwise

Source

fn remove<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove an entry from the cache

Source

fn contains<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if an entry exists and is not expired

Source

fn get_metrics<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CacheMetrics> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get current cache metrics

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear all entries from cache

Source

fn cleanup_expired<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Manually cleanup expired entries

Returns the number of expired entries removed.

Implementors§