Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cobbinma/r-cache
r-cache is an in memory key value store. It is thread safe and values can have expiry times.
https://github.com/cobbinma/r-cache
cache caching library rust
Last synced: 11 days ago
JSON representation
r-cache is an in memory key value store. It is thread safe and values can have expiry times.
- Host: GitHub
- URL: https://github.com/cobbinma/r-cache
- Owner: cobbinma
- Created: 2020-09-19T19:04:40.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-18T10:58:47.000Z (over 1 year ago)
- Last Synced: 2024-09-12T22:47:03.742Z (about 2 months ago)
- Topics: cache, caching, library, rust
- Language: Rust
- Homepage: https://crates.io/crates/r-cache
- Size: 38.1 KB
- Stars: 21
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
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
```rust
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())
}
```