pub trait Cache {
// Required methods
fn get(&self, key: &CacheKey) -> Option<Vec<u8>>;
fn put(&mut self, key: CacheKey, value: Vec<u8>);
}Expand description
Cache trait. Implementations: in-memory (default), on-disk (MVP 5).
§Examples
use mos_cache::{Cache, CacheKey, InMemoryCache};
use mos_core::ContentHash;
let mut cache = InMemoryCache::default();
let key = CacheKey(ContentHash(7));
cache.put(key, vec![1, 2, 3]);
assert_eq!(cache.get(&key), Some(vec![1, 2, 3]));Required Methods§
Sourcefn get(&self, key: &CacheKey) -> Option<Vec<u8>>
fn get(&self, key: &CacheKey) -> Option<Vec<u8>>
Return a cached payload for key, if present.
§Examples
use mos_cache::{Cache, CacheKey, InMemoryCache};
use mos_core::ContentHash;
let cache = InMemoryCache::default();
assert_eq!(cache.get(&CacheKey(ContentHash(1))), None);Sourcefn put(&mut self, key: CacheKey, value: Vec<u8>)
fn put(&mut self, key: CacheKey, value: Vec<u8>)
Store value under key, replacing any previous value.
§Examples
use mos_cache::{Cache, CacheKey, InMemoryCache};
use mos_core::ContentHash;
let mut cache = InMemoryCache::default();
let key = CacheKey(ContentHash(1));
cache.put(key, vec![9]);
assert_eq!(cache.get(&key), Some(vec![9]));