pub struct CacheLog { /* private fields */ }
Expand description
CacheLog keeps track of the original and current values of each key accessed. By tracking original values, we can detect and eliminate write patterns where a key is changed temporarily and then reset to its original value
Implementations§
Source§impl CacheLog
impl CacheLog
pub fn take_writes(self) -> Vec<(CacheKey, Option<CacheValue>)>
Sourcepub fn get_value(&self, key: &CacheKey) -> ValueExists
pub fn get_value(&self, key: &CacheKey) -> ValueExists
Returns a value corresponding to the key.
Sourcepub fn add_read(
&mut self,
key: CacheKey,
value: Option<CacheValue>,
) -> Result<(), ReadError>
pub fn add_read( &mut self, key: CacheKey, value: Option<CacheValue>, ) -> Result<(), ReadError>
The first read for a given key is inserted in the cache. For an existing cache entry checks if reads are consistent with previous reads/writes.
Sourcepub fn add_write(&mut self, key: CacheKey, value: Option<CacheValue>)
pub fn add_write(&mut self, key: CacheKey, value: Option<CacheValue>)
Adds a write entry to the cache.
Sourcepub fn merge_left(&mut self, rhs: CacheLog) -> Result<(), MergeError>
pub fn merge_left(&mut self, rhs: CacheLog) -> Result<(), MergeError>
Merges two cache logs in a way that preserves the first read (from self) and the last write (from rhs) for the same key in both caches. The merge succeeds if the first read in the right cache for a key ‘k’ is consistent with the last read/write in the self cache.
Example:
Cache1: Cache2: k1 => v1 k1 => v1’ k2 => v2 k3 => v3
Merged Cache: k1 => v1.merge(v1’) <- preserves the first read and the last write for ‘k1’ k2 => v2 k3 => v3
pub fn merge_writes_left(&mut self, rhs: CacheLog) -> Result<(), MergeError>
pub fn merge_reads_left(&mut self, rhs: CacheLog) -> Result<(), MergeError>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl From<StorageInternalCache> for CacheLog
impl From<StorageInternalCache> for CacheLog
Source§fn from(val: StorageInternalCache) -> Self
fn from(val: StorageInternalCache) -> Self
Auto Trait Implementations§
impl Freeze for CacheLog
impl RefUnwindSafe for CacheLog
impl Send for CacheLog
impl Sync for CacheLog
impl Unpin for CacheLog
impl UnwindSafe for CacheLog
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
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