pub struct CachingObjectHandle<S> { /* private fields */ }
Expand description
A wrapper handle around a ReadObjectHandle
which provides a memory cache for its contents.
Contents are fetched as needed and can be evicted (for example due to memory pressure).
Implementations§
Source§impl<S: ReadObjectHandle> CachingObjectHandle<S>
impl<S: ReadObjectHandle> CachingObjectHandle<S>
pub fn new(source: S) -> Self
Sourcepub async fn read(&self, offset: usize) -> Result<CachedChunk, Error>
pub async fn read(&self, offset: usize) -> Result<CachedChunk, Error>
Returns a reference to the chunk (up to CHUNK_SIZE
bytes) containing offset
. If the
data is already cached, this does not require reading from source
.
offset
must be less than the size of source
.
Sourcepub fn purge(&self)
pub fn purge(&self)
Purges unused extents, freeing unused memory. This follows a second-chance algorithm: unused extents will be marked for purging the first time this is called, and if they are not used again by the next time this is called, they will be deallocated. This is intended to be run regularly, e.g. on a timer.
Trait Implementations§
Source§impl<S: ReadObjectHandle> ObjectHandle for CachingObjectHandle<S>
impl<S: ReadObjectHandle> ObjectHandle for CachingObjectHandle<S>
Source§fn object_id(&self) -> u64
fn object_id(&self) -> u64
Returns the object identifier for this object which will be unique for the store that the
object is contained in, but not necessarily unique within the entire system.
Source§fn allocate_buffer(&self, size: usize) -> BufferFuture<'_>
fn allocate_buffer(&self, size: usize) -> BufferFuture<'_>
Allocates a buffer for doing I/O (read and write) for the object.
Source§fn block_size(&self) -> u64
fn block_size(&self) -> u64
Returns the filesystem block size, which should be at least as big as the device block size,
but not necessarily the same.
impl<S> Sync for CachingObjectHandle<S>
Auto Trait Implementations§
impl<S> !Freeze for CachingObjectHandle<S>
impl<S> !RefUnwindSafe for CachingObjectHandle<S>
impl<S> Send for CachingObjectHandle<S>where
S: Send,
impl<S> Unpin for CachingObjectHandle<S>where
S: Unpin,
impl<S> UnwindSafe for CachingObjectHandle<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more