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: Self) -> Result<(), MergeError>
pub fn merge_left(&mut self, rhs: Self) -> 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