Expand description
Write-through cache that synchronously persists every write to a backing store.
Unlike write-behind (write-back) caching — where dirty entries are
flushed lazily — a write-through cache propagates every put to the
backing store before returning to the caller. This guarantees that
the backing store is always consistent with the cache at the cost of
write latency.
§Read path (write-allocate)
On a cache miss, get falls back to the backing store. If the store
returns a value, the entry is inserted into the cache (write-allocate) so
subsequent reads are served locally.
§Example
use oximedia_cache::write_through::{WriteThroughCache, InMemoryStore};
let store: InMemoryStore<String, Vec<u8>> = InMemoryStore::new();
let mut cache = WriteThroughCache::new(32, store);
cache.put("key".to_string(), vec![1, 2, 3]).expect("put failed");
assert!(cache.get(&"key".to_string()).is_some());Structs§
- InMemory
Store - A simple in-memory
BackingStorebacked by aHashMap. - Write
Through Cache - Write-through cache that synchronously persists every write.
- Write
Through Stats - Snapshot of
WriteThroughCachestatistics.
Enums§
- Store
Error - Errors that can occur during backing-store operations.
Traits§
- Backing
Store - Abstraction over a synchronous persistent store.