pub struct CachingDevice { /* private fields */ }Expand description
LRU read-cache wrapper.
§It caches a READ device, and writes through one only if it has one
This took an Arc<dyn BlockDevice> — the read write trait — and
every driver in this family mounts a volume through an
Arc<dyn BlockRead>. So a read-only mount could not wrap it at all,
and four of the six drivers used no cache: not by choice, but
because it was not expressible.
The read path never needed to write. It holds the read half now, and
the writable half only when the caller had one to give:
CachingDevice::new for a device that can be written,
CachingDevice::read_only for one that cannot. A write to a cache
built the second way is [Error::ReadOnly], which is what the
underlying device would have said.
Implementations§
Source§impl CachingDevice
impl CachingDevice
Sourcepub fn new(
inner: Arc<dyn BlockDevice>,
block_size: u64,
capacity: usize,
) -> Arc<Self> ⓘ
pub fn new( inner: Arc<dyn BlockDevice>, block_size: u64, capacity: usize, ) -> Arc<Self> ⓘ
Cache a device that can be written. Writes invalidate the
entries they overlap and go through to inner.
Sourcepub fn read_only(
inner: Arc<dyn BlockRead>,
block_size: u64,
capacity: usize,
) -> Arc<Self> ⓘ
pub fn read_only( inner: Arc<dyn BlockRead>, block_size: u64, capacity: usize, ) -> Arc<Self> ⓘ
Cache a device that is only ever read.
The case every driver here actually has: a volume mounted for
reading, behind a BlockRead that was never a BlockDevice.