macro_rules! rumtk_cache_get_mut {
( $cache:expr, $key:expr, $default_function:expr ) => { ... };
}Expand description
Retrieves the cached item in mutable mode. What this means is that the internal Spin Lock
is set to write. Therefore, this macro will block until all read requests are satisfied. Any further read
requests will be blocked until you finish making use of the item. Avoid using this macro often unless
the cache usage is limited to safe interfaces. You are essentially bypassing the no globals ethos and
thus these APIs should be used with care!!!!!!
use rumtk_core::{rumtk_cache_fetch, rumtk_cache_push, rumtk_cache_get, rumtk_cache_get_mut};
use rumtk_core::cache::{new_cache, LazyRUMCache, cache_push, cache_get};
use std::sync::Arc;
type StringCache = LazyRUMCache<String, Vec<String>>;
fn init_cache(k: &String) -> Vec<String> {
vec![]
}
let mut cache: StringCache = new_cache();
static mut DEFAULT_VEC: Vec<String> = vec![];
let test_key: String = String::from("Hello World");
let test_value: String = String::from("?????");
rumtk_cache_fetch!(
&raw mut cache,
&test_key,
init_cache
);
rumtk_cache_get_mut!(
&raw mut cache,
&test_key,
&mut DEFAULT_VEC
).push(test_value.clone());
let v = rumtk_cache_get!(
&raw mut cache,
&test_key,
&DEFAULT_VEC
);
assert_eq!(test_value.as_str(), v.get(0).unwrap().as_str(), "The inserted key is not the same to what was passed as input!");