#key-value-store #cache #thread-safe #memory #times #expiry #set-key

r-cache

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

15 releases

0.5.0 Feb 18, 2023
0.4.5 Nov 18, 2022
0.4.4 Dec 13, 2021
0.4.3 Aug 14, 2021
0.3.0 Oct 18, 2020

#127 in Caching

Download history 665/week @ 2023-12-06 475/week @ 2023-12-13 181/week @ 2023-12-20 64/week @ 2023-12-27 451/week @ 2024-01-03 468/week @ 2024-01-10 522/week @ 2024-01-17 487/week @ 2024-01-24 371/week @ 2024-01-31 451/week @ 2024-02-07 593/week @ 2024-02-14 688/week @ 2024-02-21 635/week @ 2024-02-28 386/week @ 2024-03-06 522/week @ 2024-03-13 424/week @ 2024-03-20

2,085 downloads per month
Used in ndproxy

MIT/Apache

11KB
206 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();
            }
        }
    });

    cache.set(KEY, VALUE, None);

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

Dependencies

~1–7.5MB
~20K SLoC