Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cobbinma/r-cache

r-cache is an in memory key value store. It is thread safe and values can have expiry times.
https://github.com/cobbinma/r-cache

cache caching library rust

Last synced: 11 days ago
JSON representation

r-cache is an in memory key value store. It is thread safe and values can have expiry times.

Awesome Lists containing this project

README

        

r-cache




A simple caching library





Crates.io version



Download



docs.rs docs


r-cache is an in memory key value store. It is thread safe and values can have expiry times.

### Example

```rust
use async_std::sync::Arc;
use async_std::task;
use r_cache::cache::Cache;
use std::time::Duration;

const KEY: i8 = 0;
const VALUE: &str = "VALUE";

#[async_std::main]
async fn main() {
let cache = Arc::new(Cache::new(Some(Duration::from_secs(5 * 60))));
task::spawn({
let cache = Arc::clone(&cache);
async move {
loop {
task::sleep(Duration::from_secs(10 * 60)).await;
cache.remove_expired();
}
}
});

cache.set(KEY, VALUE, None);

assert_eq!(VALUE, cache.get(&KEY).unwrap())
}
```