WeaveDocs
Strand Blobs

Chunks and Cache

Chunk layout and cache for Strand Blobs — BLAKE3 chunking, ChunkCache for hot reads, and dedup statistics across blobs.

Purpose

Chunked blob storage with deduplication, cache, writer/reader APIs, repair, metrics, and policy hooks.

This page follows the real source shape for Strand Blobs and explains the workflow a developer is likely to use first.

Developer workflow

Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.

Primary types to know

  • AllowAllBlobPolicy — models/strand-blobs/src/policy.rs
  • BlobConfig — models/strand-blobs/src/config.rs
  • BlobEntry — models/strand-blobs/src/chunk.rs
  • BlobId — models/strand-blobs/src/blob.rs
  • BlobInfo — models/strand-blobs/src/blob.rs
  • BlobMetadata — models/strand-blobs/src/blob.rs
  • BlobMetrics — models/strand-blobs/src/metrics.rs
  • BlobMetricsSnapshot — models/strand-blobs/src/metrics.rs
  • BlobReader — models/strand-blobs/src/reader.rs
  • BlobStore — models/strand-blobs/src/store.rs
  • BlobWriter — models/strand-blobs/src/writer.rs
  • ChunkCache — models/strand-blobs/src/cache.rs

Example shape

use bytes::Bytes;
use strand_blobs::{BlobConfig, ChunkCache, ChunkIndex, CompressionType};

fn main() {
    // The blob store caches recently read chunks in an LRU keyed by chunk index.
    // 4 MiB is a sensible default for hot path metadata; tune up for cold reads.
    let cache = ChunkCache::new(4 * 1024 * 1024);
    cache.insert(0, Bytes::from_static(b"chunk-0"));
    cache.insert(1, Bytes::from_static(b"chunk-1"));

    // Lookups are constant-time and update hit/miss counters used by metrics().
    let hit = cache.get(&0);
    let miss = cache.get(&99);
    assert!(hit.is_some());
    assert!(miss.is_none());

    // BlobConfig controls the chunk size and compression applied at put time.
    let cfg = BlobConfig {
        chunk_size: 1024 * 1024,
        compression: CompressionType::Zstd,
        ..BlobConfig::default()
    };
    let _ = ChunkIndex::default();

    println!(
        "cache_entries={} cache_hits={} cache_misses={} chunk_size={}",
        cache.len(),
        cache.hits(),
        cache.misses(),
        cfg.chunk_size,
    );
}