pub struct Cache<E: Storage + Metrics, V: Codec> { /* private fields */ }Expand description
Implementation of Cache storage.
Implementations§
Source§impl<E: Storage + Metrics, V: Codec> Cache<E, V>
impl<E: Storage + Metrics, V: Codec> Cache<E, V>
Sourcepub async fn init(context: E, cfg: Config<V::Cfg>) -> Result<Self, Error>
pub async fn init(context: E, cfg: Config<V::Cfg>) -> Result<Self, Error>
Initialize a new Cache instance.
The in-memory index for Cache is populated during this call
by replaying the journal.
Sourcepub async fn get(&self, index: u64) -> Result<Option<V>, Error>
pub async fn get(&self, index: u64) -> Result<Option<V>, Error>
Retrieve an item from the Cache.
Sourcepub fn next_gap(&self, index: u64) -> (Option<u64>, Option<u64>)
pub fn next_gap(&self, index: u64) -> (Option<u64>, Option<u64>)
Retrieve the next gap in the Cache.
Sourcepub fn missing_items(&self, start: u64, max: usize) -> Vec<u64>
pub fn missing_items(&self, start: u64, max: usize) -> Vec<u64>
Returns up to max missing items starting from start.
This method iterates through gaps between existing ranges, collecting missing indices
until either max items are found or there are no more gaps to fill.
Sourcepub async fn prune(&mut self, min: u64) -> Result<(), Error>
pub async fn prune(&mut self, min: u64) -> Result<(), Error>
Prune Cache to the provided min.
If this is called with a min lower than the last pruned, nothing will happen.
Sourcepub async fn put(&mut self, index: u64, value: V) -> Result<(), Error>
pub async fn put(&mut self, index: u64, value: V) -> Result<(), Error>
Store an item in the Cache.
If the index already exists, put does nothing and returns.
Sourcepub async fn put_sync(&mut self, index: u64, value: V) -> Result<(), Error>
pub async fn put_sync(&mut self, index: u64, value: V) -> Result<(), Error>
Stores an item in the Cache and syncs it, plus any other pending writes, to disk.
If the index already exists, the cache is just synced.
Trait Implementations§
Auto Trait Implementations§
impl<E, V> Freeze for Cache<E, V>
impl<E, V> !RefUnwindSafe for Cache<E, V>
impl<E, V> Send for Cache<E, V>where
V: Send,
impl<E, V> Sync for Cache<E, V>where
V: Sync,
impl<E, V> Unpin for Cache<E, V>
impl<E, V> !UnwindSafe for Cache<E, V>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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