Skip to main content

Module write_through

Module write_through 

Source
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§

InMemoryStore
A simple in-memory BackingStore backed by a HashMap.
WriteThroughCache
Write-through cache that synchronously persists every write.
WriteThroughStats
Snapshot of WriteThroughCache statistics.

Enums§

StoreError
Errors that can occur during backing-store operations.

Traits§

BackingStore
Abstraction over a synchronous persistent store.