#What is the best way to maintain a mutable state that would be accessible throughout the application
5 messages · Page 1 of 1 (latest)
my current cache is using kv, the example above is in-memory using moka
pub fn include_disks(result: &mut Statistics) {
let store = get_cache();
let disk_bucket = store.bucket::<&str, Json<Vec<Disk>>>(None).unwrap();
match disk_bucket.get(&"disks") {
Ok(Some(disks)) => {
result.storage = disks.into_inner();
}
_ => {
result.storage = vec![];
}
}
}
pub fn get_cache() -> Store {
let cfg = Config::load("./cache/store").unwrap_or_else(|_| Config::new("./cache/store"));
Store::new(cfg).unwrap()
// ^^^^^^^^^^^^^^^^^^^^^^^^ this is where it panicks
}
thread 'tokio-runtime-worker' panicked at src\lib.rs:37:25:
called `Result::unwrap()` on an `Err` value: Sled(Io(Custom { kind: Other, error: "could not acquire lock on \"./cache/store\\\\db\": Os { code: 33, kind: Uncategorized, message: \"The process cannot access the file because another process has locked a portion of the file.\" }" }))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace