pub struct CacheableKvStore<S, C> { /* private fields */ }Expand description
A read-through cache adapter that wraps a KvStore with a Cache.
get(k)— checks the cache first; on a miss, fetches from the store, populates the cache, and returns the value. The mutex lock is not held while calling the underlying store, so concurrent readers are never blocked by store I/O.put(k, v)— writes to the store immediately and then invalidates the cached entry to prevent stale reads.delete(k)— deletes from the store and invalidates the cached entry.- All other
KvStoremethods (transactions, snapshots, iteration, …) delegate directly to the inner store without cache involvement.
§Type parameters
S: aKvStoreimplementor.C: aCache<Vec<u8>, Vec<u8>>implementor that is alsoSend.
Implementations§
Source§impl<S, C> CacheableKvStore<S, C>
impl<S, C> CacheableKvStore<S, C>
Trait Implementations§
Source§impl<S, C> KvStore for CacheableKvStore<S, C>
impl<S, C> KvStore for CacheableKvStore<S, C>
Source§fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, StoreError>
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, StoreError>
Retrieve the value associated with
key, or None if it is absent.Source§fn put(&self, key: &[u8], value: &[u8]) -> Result<(), StoreError>
fn put(&self, key: &[u8], value: &[u8]) -> Result<(), StoreError>
Insert or overwrite a key-value pair.
Source§fn delete(&self, key: &[u8]) -> Result<(), StoreError>
fn delete(&self, key: &[u8]) -> Result<(), StoreError>
Remove a key. No-op if the key is absent.
Source§fn range<'a>(
&'a self,
lo: &[u8],
hi: &[u8],
) -> Result<RangeIter<'a>, StoreError>
fn range<'a>( &'a self, lo: &[u8], hi: &[u8], ) -> Result<RangeIter<'a>, StoreError>
Return all key-value pairs whose keys fall within
[lo, hi),
in ascending key order.Source§fn iter<'a>(&'a self) -> Result<RangeIter<'a>, StoreError>
fn iter<'a>(&'a self) -> Result<RangeIter<'a>, StoreError>
Iterate all key-value pairs in the store in ascending key order. Read more
Source§fn transaction(&self) -> Result<Box<dyn KvTxn + '_>, StoreError>
fn transaction(&self) -> Result<Box<dyn KvTxn + '_>, StoreError>
Begin an explicit write transaction. Read more
Source§fn snapshot(&self) -> Result<Box<dyn KvSnapshot + '_>, StoreError>
fn snapshot(&self) -> Result<Box<dyn KvSnapshot + '_>, StoreError>
Capture a point-in-time read-only snapshot of the store.
Source§fn flush(&self) -> Result<(), StoreError>
fn flush(&self) -> Result<(), StoreError>
Ensure all committed data has been written to durable storage. Read more
Source§fn get_many(&self, keys: &[&[u8]]) -> Result<Vec<Option<Vec<u8>>>, StoreError>
fn get_many(&self, keys: &[&[u8]]) -> Result<Vec<Option<Vec<u8>>>, StoreError>
Retrieve values for multiple keys in a single call. Read more
Source§fn get_ref<'a>(
&'a self,
key: &[u8],
) -> Result<Option<Cow<'a, [u8]>>, StoreError>
fn get_ref<'a>( &'a self, key: &[u8], ) -> Result<Option<Cow<'a, [u8]>>, StoreError>
Retrieve a value as a
std::borrow::Cow, avoiding a clone when the
backend can return a borrowed slice. Read moreSource§fn range_rev<'a>(
&'a self,
lo: &[u8],
hi: &[u8],
) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, Vec<u8>), StoreError>> + 'a>, StoreError>
fn range_rev<'a>( &'a self, lo: &[u8], hi: &[u8], ) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, Vec<u8>), StoreError>> + 'a>, StoreError>
Return all key-value pairs whose keys fall within
[lo, hi),
in descending key order. Read moreSource§fn prefix_scan<'a>(
&'a self,
prefix: &[u8],
) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, Vec<u8>), StoreError>> + 'a>, StoreError>
fn prefix_scan<'a>( &'a self, prefix: &[u8], ) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, Vec<u8>), StoreError>> + 'a>, StoreError>
Iterate all key-value pairs sharing the given
prefix, in ascending
key order. Read moreSource§fn batch_write(&self, pairs: &[(&[u8], &[u8])]) -> Result<(), StoreError>
fn batch_write(&self, pairs: &[(&[u8], &[u8])]) -> Result<(), StoreError>
Insert multiple key-value pairs atomically in a single batch. Read more
Source§fn batch_delete(&self, keys: &[&[u8]]) -> Result<(), StoreError>
fn batch_delete(&self, keys: &[&[u8]]) -> Result<(), StoreError>
Delete multiple keys atomically in a single batch. Read more
Source§fn count(&self) -> Result<u64, StoreError>
fn count(&self) -> Result<u64, StoreError>
Return the total number of keys in the store. Read more
Source§fn size_on_disk(&self) -> Result<u64, StoreError>
fn size_on_disk(&self) -> Result<u64, StoreError>
Return the approximate byte size of the store on disk. Read more
Source§fn keys<'a>(
&'a self,
) -> Result<Box<dyn Iterator<Item = Result<Vec<u8>, StoreError>> + 'a>, StoreError>
fn keys<'a>( &'a self, ) -> Result<Box<dyn Iterator<Item = Result<Vec<u8>, StoreError>> + 'a>, StoreError>
Iterate all keys (without loading values) in ascending order. Read more
Source§fn compare_and_swap(
&self,
key: &[u8],
expected: Option<&[u8]>,
new_value: &[u8],
) -> Result<bool, StoreError>
fn compare_and_swap( &self, key: &[u8], expected: Option<&[u8]>, new_value: &[u8], ) -> Result<bool, StoreError>
Atomic compare-and-swap: if the current value for
key equals
expected, replace it with new_value and return Ok(true).
If the current value does not match expected, return Ok(false). Read moreSource§fn put_with_ttl(
&self,
_key: &[u8],
_value: &[u8],
_ttl: Duration,
) -> Result<(), StoreError>
fn put_with_ttl( &self, _key: &[u8], _value: &[u8], _ttl: Duration, ) -> Result<(), StoreError>
Insert a key-value pair with a time-to-live. After
ttl has elapsed,
the key is treated as absent (expired). Read moreSource§fn expire(&self, _key: &[u8], _ttl: Duration) -> Result<(), StoreError>
fn expire(&self, _key: &[u8], _ttl: Duration) -> Result<(), StoreError>
Set a TTL on an existing key. The key must already exist. Read more
Source§fn ttl(&self, _key: &[u8]) -> Result<Option<Duration>, StoreError>
fn ttl(&self, _key: &[u8]) -> Result<Option<Duration>, StoreError>
Return the remaining TTL for a key. Read more
Source§fn persist(&self, _key: &[u8]) -> Result<bool, StoreError>
fn persist(&self, _key: &[u8]) -> Result<bool, StoreError>
Remove the TTL from a key, making it persistent. Read more
Source§fn purge_expired(&self) -> Result<u64, StoreError>
fn purge_expired(&self) -> Result<u64, StoreError>
Scan and delete all expired keys eagerly. Read more
Source§fn compact(&self) -> Result<(), StoreError>
fn compact(&self) -> Result<(), StoreError>
Trigger manual compaction on backends that support it. Read more
Auto Trait Implementations§
impl<S, C> !Freeze for CacheableKvStore<S, C>
impl<S, C> RefUnwindSafe for CacheableKvStore<S, C>where
S: RefUnwindSafe,
impl<S, C> Send for CacheableKvStore<S, C>
impl<S, C> Sync for CacheableKvStore<S, C>
impl<S, C> Unpin for CacheableKvStore<S, C>
impl<S, C> UnsafeUnpin for CacheableKvStore<S, C>where
S: UnsafeUnpin,
C: UnsafeUnpin,
impl<S, C> UnwindSafe for CacheableKvStore<S, C>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