Skip to main content

FileCache

Trait FileCache 

Source
pub trait FileCache<V> {
    // Required methods
    async fn get(&self, key: &str) -> Result<Option<V>>;
    async fn get_stale(&self, key: &str) -> Result<Option<V>>;
    async fn set(&self, key: &str, value: &V) -> Result<()>;
    async fn remove(&self, key: &str) -> Result<()>;
}
Expand description

Trait for TTL-based filesystem caching.

Provides a unified interface for caching serializable data with time-to-live validation.

async_fn_in_trait is suppressed because this trait is re-exported for use by crate consumers but is never intended to be implemented externally or used as dyn FileCache. All known implementors are in this crate, so auto-trait bounds are not a concern.

Required Methods§

Source

async fn get(&self, key: &str) -> Result<Option<V>>

Get a cached value if it exists and is valid.

§Arguments
  • key - Cache key (filename without extension)
§Returns

The cached value if it exists and is within TTL, None otherwise.

Source

async fn get_stale(&self, key: &str) -> Result<Option<V>>

Get a cached value regardless of TTL (stale fallback).

§Arguments
  • key - Cache key (filename without extension)
§Returns

The cached value if it exists, None otherwise.

Source

async fn set(&self, key: &str, value: &V) -> Result<()>

Set a cached value.

§Arguments
  • key - Cache key (filename without extension)
  • value - Value to cache
Source

async fn remove(&self, key: &str) -> Result<()>

Remove a cached value.

§Arguments
  • key - Cache key (filename without extension)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<V> FileCache<V> for FileCacheImpl<V>
where V: Serialize + for<'de> Deserialize<'de>,