rumtk_cache_get

Macro rumtk_cache_get 

Source
macro_rules! rumtk_cache_get {
    ( $cache:expr, $key:expr ) => { ... };
}
Expand description

Overrides contents in cache at key K. No checks are performed for the existence of the key in the cache. Be careful not to override necessary data.

use rumtk_core::{rumtk_cache_fetch, rumtk_cache_push, rumtk_cache_get};
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();

let test_key: String = String::from("Hello World");
let test_value: String = String::from("?????");

rumtk_cache_fetch!(
    &mut cache,
    &test_key,
    init_cache
);

rumtk_cache_push!(
    &mut cache,
    &test_key,
    &vec![test_value.clone()]
);

let v = rumtk_cache_get!(
    &mut cache,
    &test_key
).unwrap();

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!");