#cache #async

r-cache

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

13 releases

Uses new Rust 2021

0.4.4 Dec 13, 2021
0.4.3 Aug 14, 2021
0.4.1 Jun 7, 2021
0.4.0 Jan 11, 2021
0.1.0 Sep 19, 2020

#21 in Caching

Download history 7293/week @ 2021-09-25 739/week @ 2021-10-02 29/week @ 2021-10-09 5/week @ 2021-10-16 6/week @ 2021-10-23 1/week @ 2021-10-30 24/week @ 2021-11-06 9/week @ 2021-11-13 36/week @ 2021-11-20 31/week @ 2021-11-27 47/week @ 2021-12-04 26/week @ 2021-12-11 5/week @ 2021-12-18 2/week @ 2021-12-25 41/week @ 2022-01-01 201/week @ 2022-01-08

250 downloads per month

MIT/Apache

10KB
207 lines

r-cache

A simple caching library


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

Example

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().await;
            }
        }
    });

    cache.set(KEY, VALUE, None).await;

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

Dependencies

~81KB