Cache

Trait Cache 

Source
pub trait Cache: DeserializeOwned {
    type AcceptStorePoint: BaseStorePoint;

    // Provided methods
    fn refresh_cache<P: AsRef<Path> + Send>(
        base: &Self::AcceptStorePoint,
        suffix: P,
        client: Client,
        url: &str,
    ) -> impl Future<Output = Result<Self>> + Send { ... }
    fn try_cache<P: AsRef<Path> + Send>(
        base: &Self::AcceptStorePoint,
        suffix: P,
        client: Client,
        url: &str,
    ) -> impl Future<Output = Result<Self>> + Send { ... }
    fn check_cache<P: AsRef<Path> + Send>(
        base: &Self::AcceptStorePoint,
        suffix: P,
        client: Client,
        url: &str,
        sha: SHA,
    ) -> impl Future<Output = Result<Self>> + Send { ... }
    fn builder() -> CacheBuilder<Self::AcceptStorePoint, Self>
       where Self::AcceptStorePoint: Clone { ... }
}

Required Associated Types§

Provided Methods§

Source

fn refresh_cache<P: AsRef<Path> + Send>( base: &Self::AcceptStorePoint, suffix: P, client: Client, url: &str, ) -> impl Future<Output = Result<Self>> + Send

Source

fn try_cache<P: AsRef<Path> + Send>( base: &Self::AcceptStorePoint, suffix: P, client: Client, url: &str, ) -> impl Future<Output = Result<Self>> + Send

this will check file exist or not. if the file exist, it will return the data from disk. if the file not exist, it will fetch the data from the source and save it to the disk, then return the data. a dirty way to avoid async trait warning, you should see this as async fn try_cache -> anyhow::Result<Self>;

Source

fn check_cache<P: AsRef<Path> + Send>( base: &Self::AcceptStorePoint, suffix: P, client: Client, url: &str, sha: SHA, ) -> impl Future<Output = Result<Self>> + Send

  1. the file exist and the sha is valid, return the data from disk.
  2. the file exist and the sha is invalid, fetch the data from the source and save it to the disk, then return the data.
  3. the file not exist, fetch the data from the source and save it to the disk, then return the data.
Source

fn builder() -> CacheBuilder<Self::AcceptStorePoint, Self>
where Self::AcceptStorePoint: Clone,

Return a builder for the cache.

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§