I have started on basic-webserver PR#17 to implement a simple KV cache for the webserver. This will also be helpful for when we have a builtin binary encoder/decoder, as this can be upgraded to store the value in the platform side, without manually handling on the application side.
Unfortunately, I think I'm blocked on ideas for how to actually store the data in-memory in Rust. I've implemented the rest of the functionality, and added an example app to test the feature.
I am looking for some assistance for how to implement the following in platform/src/lib.rs
.
How can I allocate some memory, and make a thread-safe hyper friendly data structure to store the values in? How should one do this in a Rusty way?
#[roc_fn(name = "getKV")]
fn get_kv(key: u64) -> roc_std::RocResult<roc_std::RocList<u8>, glue_manual::CacheError> {
// todo - how to implement this?
roc_std::RocResult::err(glue_manual::CacheError::NotFound)
}
#[roc_fn(name = "setKV")]
fn set_kv(key: u64, value: &roc_std::RocList<u8>) {
// todo - how to implement this?
}
Maybe use a HashMap?
Last updated: Jul 05 2025 at 12:14 UTC