This crate provides concurrent-safe typedcache with expiration capabilities.
Add this to your Cargo.toml
:
toml
[build-dependencies]
typedcache = "0.1"
```rust use std::time::Duration;
use typedcache::typed::TypedMap;
async fn main() { let cache = typedcache::cache("test".into()).await; cache .add( TestKey("keyerpiredafter1s".into()), Duration::fromsecs(1), TestValue(1), ) .await; tokio::time::sleep(Duration::fromsecs(2)).await; assert!(cache .get(&TestKey("keyerpiredafter1s".into())) .await .is_none()); }
pub struct TestKey(String);
impl TypedMap for TestKey { type Value = TestValue; }
pub struct TestValue(isize);
```
Typed any map for rust: typedmap
Concurrency-safe golang caching library with expiration capabilities: cache2go
Dual-licensed under the MIT license and the Apache License (Version 2.0).
See LICENSE-MIT and LICENSE-APACHE for details.