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.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for Cache<K, V>
impl<K, V> RefUnwindSafe for Cache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for Cache<K, V>
impl<K, V> Sync for Cache<K, V>
impl<K, V> Unpin for Cache<K, V>
impl<K, V> UnsafeUnpin for Cache<K, V>
impl<K, V> UnwindSafe for Cache<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more