pub struct Cache<K, V> { /* private fields */ }Expand description
An in-memory key-value cache that is automatically synced to disk.
The goal is simplicity, ease of use, and ease of distribution. All data is stored in a single file, which is automatically loaded into memory when using the cache.
§Warning
§No Edits
The biggest constraint for the cache is that values should never change for a given key. There is no update possible; if a value is reinserted a second time with a different value but the same key, an error will arise.
This is important to keep the file format simple: there is no metadata, no headers, just a plain separator between each cache entry. Therefore, it isn’t possible to edit previously saved content.
§No Big Files
The cache isn’t optimized for space; use it for small caches.
Implementations§
Source§impl<K, V> Cache<K, V>where
K: CacheKey,
V: CacheValue,
impl<K, V> Cache<K, V>where
K: CacheKey,
V: CacheValue,
Sourcepub fn new<P>(path: P, option: CacheOption) -> Cache<K, V>
pub fn new<P>(path: P, option: CacheOption) -> Cache<K, V>
Create a new cache and load the data from the provided path if it exists.
Sourcepub fn insert(&mut self, key: K, value: V) -> Result<(), CacheError<K, V>>
pub fn insert(&mut self, key: K, value: V) -> Result<(), CacheError<K, V>>
Insert a new item to the cache.
Panic if an item with a different value exists in the cache.