#key-value-store #thread-safe #cache #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

#161 in Caching

Download history 977/week @ 2024-07-19 1318/week @ 2024-07-26 1003/week @ 2024-08-02 1036/week @ 2024-08-09 1053/week @ 2024-08-16 950/week @ 2024-08-23 1172/week @ 2024-08-30 825/week @ 2024-09-06 881/week @ 2024-09-13 978/week @ 2024-09-20 1113/week @ 2024-09-27 1205/week @ 2024-10-04 1468/week @ 2024-10-11 382/week @ 2024-10-18 401/week @ 2024-10-25 584/week @ 2024-11-01

3,075 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–5.5MB
~21K SLoC