| Crates.io | gs-rust-cache |
| lib.rs | gs-rust-cache |
| version | 0.1.4 |
| created_at | 2025-01-23 19:51:32.007+00 |
| updated_at | 2025-07-28 22:56:01.356944+00 |
| description | Thread safe cache developed using lru crate(https://crates.io/crates/lru) as its core. Supports LRU, positive and negative TTLs and miss handler function. |
| homepage | https://github.com/dduartec/rust-cache |
| repository | https://github.com/dduartec/rust-cache.git |
| max_upload_size | |
| id | 1528150 |
| size | 43,241 |
This project is a simple caching library written in Rust. It provides an easy-to-use interface for storing and retrieving data with high performance. The library supports various caching strategies and is designed to be lightweight and efficient.
Add the following to your Cargo.toml:
[dependencies]
rust-cache = "0.1.3"
Here's a basic example of how to use the Rust Cache library:
use gs_rust_cache::Cache;
fn miss_handler(key: &i32, data: &mut i32, adhoc_code: &mut u8, _: &[&dyn Any]) -> bool {
// Your Code Here
*data = 123;
*adhoc_code = 200;
true
}
fn main() {
let mut cache = Cache::new(
3,
miss_handler,
Duration::from_millis(200),
Duration::from_millis(100),
);
let key = 456;
let (value, adhoc_code, is_hit) = cache.retrieve_or_compute(&key); // first one is calculated
let (value_1, adhoc_code_1, is_hit_1) = cache.retrieve_or_compute(&key); // afterwards it is retrieved
assert_eq!(value, value_1);
assert_eq!(adhoc_code, adhoc_code_1);
assert!(is_hit); // is_hit is false because the value was computed
assert!(is_hit_1); // is_hit_1 is true because the value was retrieved from the cache
}
This project is licensed under the MIT License.