pub trait TreeBlockCache: Send + Sync {
// Required methods
fn get(&self, addr: u64) -> Option<Arc<TreeBlock>>;
fn put(&self, addr: u64, block: Arc<TreeBlock>);
fn invalidate(&self, addr: u64);
}Expand description
Pluggable cache for parsed TreeBlocks, consulted by
BlockReader::read_tree_block.
The trait is Send + Sync and uses &self methods so a single cache
can be shared across threads (and, eventually, across multiple
BlockReader instances in a reader pool). Implementations use
interior mutability — typically a Mutex<lru::LruCache<...>> or
similar.
btrfs-disk does not provide an LRU implementation: keeping the
crate dependency-light is more important than convenience here.
The btrfs-fs crate ships an LruTreeBlockCache that most
embedders will use.
Required Methods§
Sourcefn get(&self, addr: u64) -> Option<Arc<TreeBlock>>
fn get(&self, addr: u64) -> Option<Arc<TreeBlock>>
Look up a tree block by logical address. Returns None on miss.
Sourcefn put(&self, addr: u64, block: Arc<TreeBlock>)
fn put(&self, addr: u64, block: Arc<TreeBlock>)
Insert a freshly-read tree block into the cache. Implementations decide eviction policy.
Sourcefn invalidate(&self, addr: u64)
fn invalidate(&self, addr: u64)
Drop a single entry. Used by writers (e.g. the transaction crate
during CoW) to invalidate stale blocks.