rtcache
A read-through/write-back caching library.
To create a cache, first define a store and implement the Store trait:
Then, initialize the cache:
let mut data = new;
data.insert;
let data = new;
let mut cache = new.await;
Use Cache::get to access values in the cache.
// The store's `fetch` function will be used if this key isn't in the cache already.
let value = cache.get.await.unwrap;
Values may be modified using interior mutability:
*value.lock.await = Stringfrom;
The Store's update function is called when a key/value pair is evicted from the cache. This is a good place to update the cache's backing store in case there were any modifications to the value.
See examples/examples.rb for more.
Important note: The cache internally stores values in Arcs and Cache::get returns a cloned pointer. If an Arc<V> has a reference count more than one, the Arc is in use outside of the cache and the key/value pair will not be evicted from the cache.