rumtk_cache_push

Macro rumtk_cache_push 

Source
macro_rules! rumtk_cache_push {
    ( $cache:expr, $key:expr, $val: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};
use rumtk_core::cache::{new_cache, LazyRUMCache, cache_push};
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!(
    &raw mut cache,
    &test_key,
    init_cache
);

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

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