use moka::sync::Cache;
#[derive(Clone)]
pub struct MemCache<K, V> {
variables: Cache<K, V>,
}
impl<K, V> MemCache<K, V>
where
K: std::hash::Hash + Eq + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
{
pub fn new(capacity: usize) -> Self {
Self {
variables: Cache::new(capacity as u64),
}
}
pub fn set(
&self,
key: K,
value: V,
) {
self.variables.insert(key, value);
}
pub fn get(
&self,
key: &K,
) -> Option<V> {
self.variables.get(key)
}
pub fn remove(
&self,
key: &K,
) {
self.variables.remove(key);
}
pub fn iter(&self) -> moka::sync::Iter<'_, K, V> {
self.variables.iter()
}
}