Strand Blobs
Chunks and Cache
Cache byte capacity and optional compression in BlobConfig.
ChunkCache caches packed chunks by Strand sequence and tracks bytes, entries, hits and misses. BlobConfig.compression is an Option<CompressionType>; availability of compression algorithms follows Cargo features. A deduplication hash and a cache hit do not certify a peer’s identity or remote availability.
The example requires the zstd Cargo feature on strand-blobs. It is checked against source signatures; it was not compiled or run during this documentation pass.
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.
// Example capacity: 4 MiB of cached chunk bytes.
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 update hit/miss counters.
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: Some(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,
);
}