#typed #cache #expiration #capabilities #concurrent-safe

typedcache

Concurrent-safe typedcache with expiration capabilities

3 unstable releases

0.2.1 May 9, 2023
0.2.0 Apr 22, 2023
0.1.0 Apr 7, 2023

#10 in #expiration

Download history 29/week @ 2024-02-24 1/week @ 2024-03-02 1/week @ 2024-03-09 36/week @ 2024-03-30 3/week @ 2024-04-06 65/week @ 2024-04-13

104 downloads per month

MIT/Apache

30KB
668 lines

typedcache

Crates.io License Build Status

This crate provides concurrent-safe typedcache with expiration capabilities.

Usage

Add this to your Cargo.toml:

[build-dependencies]
typedcache = "0.2"

Example

use std::time::Duration;

use typedcache::typed::TypedMap;

#[tokio::main]
async fn main() {
    let cache = typedcache::cache("test".into());
    cache
        .add(
            TestKey("key_erpired_after_1s".into()),
            Duration::from_secs(1),
            TestValue(1),
        );
    tokio::time::sleep(Duration::from_secs(2)).await;
    assert!(cache
        .get(&TestKey("key_erpired_after_1s".into()))
        .is_none());
}

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct TestKey(String);

impl TypedMap for TestKey {
    type Value = TestValue;
}

pub struct TestValue(isize);

Acknowledgements

Typed any map for rust: typedmap

Concurrency-safe golang caching library with expiration capabilities: cache2go

License

Dual-licensed under the MIT license and the Apache License (Version 2.0).

See LICENSE-MIT and LICENSE-APACHE for details.

Dependencies

~3–10MB
~84K SLoC