Crates.io | typedcache |
lib.rs | typedcache |
version | 0.2.1 |
source | src |
created_at | 2023-04-07 17:48:29.198384 |
updated_at | 2023-05-09 10:01:01.549738 |
description | Concurrent-safe typedcache with expiration capabilities. |
homepage | |
repository | https://github.com/Millione/typedcache |
max_upload_size | |
id | 833079 |
size | 74,138 |
This crate provides concurrent-safe typedcache with expiration capabilities.
Add this to your Cargo.toml
:
[build-dependencies]
typedcache = "0.2"
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);
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.