Loading RustViz Engine...
Allow simultaneous concurrent reads while securing exclusive writes.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
use std::sync::RwLock;
use std::collections::HashMap;
pub struct Cache {
store: RwLock<HashMap<String, String>>,
}
impl Cache {
pub fn get(&self, k: &str) -> Option<String> {
self.store.read().unwrap().get(k).cloned()
}
pub fn set(&self, k: String, v: String) {
self.store.write().unwrap().insert(k, v);
}
}