macro_rules! rumtk_cache_fetch {
( $cache:expr, $key:expr, $func:expr ) => { ... };
}Expand description
Searches for item in global cache. If global cache lacks item, create item using factory function passed to this macro.
use crate::rumtk_core::rumtk_cache_fetch;
use crate::rumtk_core::cache::{new_cache, LazyRUMCache};
use std::sync::Arc;
type StringCache = LazyRUMCache<String, String>;
fn init_cache(k: &String) -> String {
String::from(k)
}
let mut cache: StringCache = new_cache();
let test_key: String = String::from("Hello World");
let v = rumtk_cache_fetch!(
&mut cache,
&test_key,
init_cache
);
assert_eq!(test_key.as_str(), v.as_str(), "The inserted key is not the same to what was passed as input!");