Trait Cache

Source
pub trait Cache: CondSync {
    // Required methods
    fn get_references_cache(
        &self,
        cid: Cid,
    ) -> impl Future<Output = Result<Option<Vec<Cid>>, BlockStoreError>> + CondSend;
    fn put_references_cache(
        &self,
        cid: Cid,
        references: Vec<Cid>,
    ) -> impl Future<Output = Result<(), BlockStoreError>> + CondSend;

    // Provided method
    fn references(
        &self,
        cid: Cid,
        store: &impl BlockStore,
    ) -> impl Future<Output = Result<Vec<Cid>, BlockStoreError>> + CondSend { ... }
}
Expand description

This trait abstracts caches used by the car mirror implementation. An efficient cache implementation can significantly reduce the amount of lookups into the blockstore.

At the moment, all caches are either memoization tables or informationally monotonous, so you don’t need to be careful about cache eviction.

See InMemoryCache for a quick_cache-based implementation (enable the quick-cache feature), and NoCache for disabling the cache.

Required Methods§

Source

fn get_references_cache( &self, cid: Cid, ) -> impl Future<Output = Result<Option<Vec<Cid>>, BlockStoreError>> + CondSend

This returns further references from the block referenced by given CID, if the cache is hit. Returns None if it’s a cache miss.

This isn’t meant to be called directly, instead use Cache::references.

Source

fn put_references_cache( &self, cid: Cid, references: Vec<Cid>, ) -> impl Future<Output = Result<(), BlockStoreError>> + CondSend

Populates the references cache for given CID with given references.

Provided Methods§

Source

fn references( &self, cid: Cid, store: &impl BlockStore, ) -> impl Future<Output = Result<Vec<Cid>, BlockStoreError>> + CondSend

Find out any CIDs that are linked to from the block with given CID.

This makes use of the cache via get_references_cached, if possible. If the cache is missed, then it will fetch the block, compute the references and automatically populate the cache using put_references_cached.

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.

Implementations on Foreign Types§

Source§

impl<C: Cache> Cache for &C

Source§

async fn get_references_cache( &self, cid: Cid, ) -> Result<Option<Vec<Cid>>, BlockStoreError>

Source§

async fn put_references_cache( &self, cid: Cid, references: Vec<Cid>, ) -> Result<(), BlockStoreError>

Source§

impl<C: Cache> Cache for Box<C>

Source§

async fn get_references_cache( &self, cid: Cid, ) -> Result<Option<Vec<Cid>>, BlockStoreError>

Source§

async fn put_references_cache( &self, cid: Cid, references: Vec<Cid>, ) -> Result<(), BlockStoreError>

Implementors§