Skip to main content

BlobCache

Trait BlobCache 

Source
pub trait BlobCache: Send + Sync {
    // Required methods
    fn get(
        &self,
        hash: [u8; 32],
        offset: u64,
        len: u64,
    ) -> SinkFuture<'_, Option<Bytes>>;
    fn put(
        &self,
        hash: [u8; 32],
        offset: u64,
        bytes: Bytes,
    ) -> SinkFuture<'_, ()>;

    // Provided method
    fn caches(&self) -> bool { ... }
}
Expand description

An injected content cache the Streamer consults and fills, keyed by (hash, offset) over content bytes.

Pure by design: the trait names no blob store, which is what keeps decdn-client iroh-blobs-free — a blob-store-backed implementation lives ABOVE this crate and is injected. The default is the no-op NoCache (never hits, never stores), so a caller that wants no revisit-reuse pays nothing.

On a clean finish the Streamer tees the whole verified blob to put. On a revisit it asks get for the whole blob: a whole-blob hit is served straight from the cache with no fetch, and anything less is treated as a miss and refetched in full — the store’s gap-driven resume, not the cache, is what avoids re-pulling a partial prefix today. (Serving a cached PARTIAL prefix and fetching only the complement is a planned enhancement; get already reports a partial hold as a miss so an implementer need not stitch fragments.)

Required Methods§

Source

fn get( &self, hash: [u8; 32], offset: u64, len: u64, ) -> SinkFuture<'_, Option<Bytes>>

Return cached content bytes for exactly [offset, offset + len) of hash, or None on a miss. A partial hold is a miss — the caller fetches the whole range rather than stitching a fragment.

§Errors

Whatever the backing cache raises. A miss is Ok(None), not an error.

Source

fn put(&self, hash: [u8; 32], offset: u64, bytes: Bytes) -> SinkFuture<'_, ()>

Store verified content bytes as [offset, offset + bytes.len()) of hash. A cache that does not want the range may drop it.

§Errors

Whatever the backing cache raises.

Provided Methods§

Source

fn caches(&self) -> bool

Whether this cache actually stores what it is given. A caller that would have to materialize the whole blob just to tee it here (the Streamer’s revisit tee) skips that work — and the memory it costs — when this is false. Defaults to true; a no-op cache overrides it.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§