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§
Sourcefn get(
&self,
hash: [u8; 32],
offset: u64,
len: u64,
) -> SinkFuture<'_, Option<Bytes>>
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.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".