rumtk_cache_get

Macro rumtk_cache_get 

Source
macro_rules! rumtk_cache_get {
    ( $cache:expr, $key:expr, $default_function: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();
static 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_push!(
    &raw mut cache,
    &test_key,
    &vec![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!");