caching/write_through_cache library
Write-through and write-back caches over async loaders — roadmap #508.
Both wrap an async backing store (a remote API, a database, a file) behind an in-memory map so repeated reads of the same key are served locally, and both coordinate writes to that store — the capability the read-through WriteThroughCache (roadmap #523) does not provide. They differ only in when writes reach the backing store:
- WriteThroughStore writes synchronously to the store on every
put, so the store is always current and a crash loses nothing — at the cost of one round-trip per write. - WriteBackStore buffers writes in memory and only persists them on WriteBackStore.flush, coalescing repeated writes to the same key into one store call — faster under write-heavy load, but unflushed entries are lost on a crash.
Neither evicts on its own; pair with a size-bounded map (see lru_cache) if
the key space is unbounded.
Classes
-
WriteBackStore<
K, V> - A cache that buffers writes in memory until flush persists them.
-
WriteThroughStore<
K, V> - A cache that persists every write to the backing store immediately.
Typedefs
-
CacheLoader<
K, V> = Future< V?> Function(K key) - Loads the value for a key from the backing store (null = absent).
-
CacheStorer<
K, V> = Future< void> Function(K key, V value) - Persists a key/value pair to the backing store.