threatflux_cache/lib.rs
1//! # ThreatFlux Cache
2//!
3//! A flexible async cache library for Rust with pluggable backends and serialization.
4//!
5//! ## Features
6//!
7//! - **Async-first**: Built on tokio for high-performance async operations
8//! - **Generic**: Works with any serializable key-value types
9//! - **Pluggable backends**: Filesystem, memory, or custom implementations
10//! - **JSON persistence**: Versioned snapshots for the filesystem backend
11//! - **Eviction policies**: LRU, LFU, FIFO, TTL-based eviction
12//! - **Search filters**: Query by key, timestamp, access count, category, and expiry
13//!
14//! ## Quick Start
15//!
16//! ```rust
17//! use threatflux_cache::{Cache, CacheConfig, MemoryBackend, AsyncCache};
18//! use serde::{Serialize, Deserialize};
19//!
20//! #[derive(Serialize, Deserialize, Clone)]
21//! struct MyData {
22//! content: String,
23//! }
24//!
25//! #[tokio::main]
26//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
27//! // Create a cache with default configuration and memory backend
28//! let backend = MemoryBackend::new();
29//! let cache = Cache::<String, MyData>::new(CacheConfig::default(), backend).await?;
30//!
31//! // Store a value
32//! cache.put("key1".to_string(), MyData { content: "Hello".to_string() }).await?;
33//!
34//! // Retrieve a value
35//! if let Some(data) = cache.get(&"key1".to_string()).await? {
36//! println!("Found: {}", data.content);
37//! }
38//!
39//! Ok(())
40//! }
41//! ```
42
43#![warn(missing_docs)]
44#![warn(rustdoc::missing_crate_level_docs)]
45
46pub mod backends;
47pub mod cache;
48pub mod config;
49pub mod entry;
50pub mod error;
51pub mod eviction;
52pub mod search;
53pub mod storage;
54
55#[cfg(test)]
56pub(crate) mod test_utils;
57
58// Re-export main types
59pub use cache::{AsyncCache, Cache};
60pub use config::{CacheConfig, EvictionPolicy, PersistenceConfig};
61pub use entry::{CacheEntry, EntryMetadata};
62pub use error::{CacheError, Result};
63pub use search::{SearchQuery, Searchable};
64pub use storage::StorageBackend;
65
66// Re-export backend implementations
67#[cfg(feature = "filesystem-backend")]
68pub use backends::filesystem::FilesystemBackend;
69pub use backends::memory::MemoryBackend;
70
71/// Prelude module for convenient imports
72pub mod prelude {
73 pub use crate::{
74 AsyncCache, Cache, CacheConfig, CacheEntry, CacheError, EntryMetadata, Result, Searchable,
75 StorageBackend,
76 };
77
78 #[cfg(feature = "filesystem-backend")]
79 pub use crate::FilesystemBackend;
80 pub use crate::MemoryBackend;
81}