1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! # MiniCache
//!
//! A fast, lightweight, async-compatible in-memory cache for Rust with TTL (Time-To-Live)
//! support and automatic cleanup. Perfect for async applications that need efficient caching
//! without the complexity.
//!
//! ## Features
//!
//! - **🔥 High Performance**: Millions of operations per second
//! - **⚡ Async/Await Ready**: Built for `tokio` and async applications
//! - **⏰ TTL Support**: Automatic expiration with background cleanup
//! - **🔒 Thread-Safe**: Concurrent access with `Arc` + `RwLock`
//! - **💾 Memory Efficient**: Minimal overhead per cache entry
//! - **🛠 Easy to Use**: Simple API with comprehensive examples
//!
//! ## Quick Start
//!
//! ```rust
//! use minicache::MiniCache;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() {
//! // Create cache with 60-second cleanup interval
//! let cache = MiniCache::new(Duration::from_secs(60));
//!
//! // Set a value (no expiration)
//! cache.set("user:123", "John Doe", None).await;
//!
//! // Set a value with TTL
//! cache.set("session:abc", "temp_data", Some(Duration::from_secs(300))).await;
//!
//! // Get values
//! if let Some(user) = cache.get(&"user:123").await {
//! println!("User: {}", user);
//! }
//!
//! // Check if key exists
//! if cache.contains(&"session:abc").await {
//! println!("Session is active");
//! }
//!
//! println!("Cache size: {}", cache.len().await);
//! }
//! ```
//!
//! ## TTL Usage
//!
//! ```rust
//! use minicache::MiniCache;
//! use std::time::Duration;
//! use tokio::time::sleep;
//!
//! #[tokio::main]
//! async fn main() {
//! let cache = MiniCache::new(Duration::from_millis(100));
//!
//! // Set with 200ms TTL
//! cache.set("temp", "expires soon", Some(Duration::from_millis(200))).await;
//!
//! // Value exists immediately
//! assert_eq!(cache.get(&"temp").await, Some("expires soon"));
//!
//! // Wait for expiration
//! sleep(Duration::from_millis(250)).await;
//!
//! // Value has expired
//! assert_eq!(cache.get(&"temp").await, None);
//! }
//! ```
//!
//! ## Concurrent Usage
//!
//! ```rust
//! use minicache::MiniCache;
//! use std::sync::Arc;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() {
//! let cache = Arc::new(MiniCache::new(Duration::from_secs(60)));
//! let mut handles = vec![];
//!
//! // Spawn multiple tasks
//! for i in 0..10 {
//! let cache_clone = cache.clone();
//! let handle = tokio::spawn(async move {
//! cache_clone.set(format!("key_{}", i), format!("value_{}", i), None).await;
//! });
//! handles.push(handle);
//! }
//!
//! // Wait for all tasks
//! for handle in handles {
//! handle.await.unwrap();
//! }
//!
//! println!("Total entries: {}", cache.len().await);
//! }
//! ```
//!
//! ## Performance
//!
//! Based on benchmarks (MacBook Pro M1):
//! - **Basic Reads**: ~13.7M operations/second
//! - **Basic Writes**: ~9.6M operations/second
//! - **Concurrent Access**: ~1.7M operations/second
//! - **Memory Overhead**: ~162 bytes per entry
pub use MiniCache;