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//! - **Flexible serialization**: JSON, bincode, or custom formats
11//! - **Eviction policies**: LRU, LFU, FIFO, TTL-based eviction
12//! - **Compression**: Optional compression for stored values
13//! - **Search capabilities**: Query cache entries with custom predicates
14//! - **Metrics**: Optional Prometheus metrics integration
15//!
16//! ## Quick Start
17//!
18//! ```rust
19//! use threatflux_cache::{Cache, CacheConfig, MemoryBackend, AsyncCache};
20//! use serde::{Serialize, Deserialize};
21//!
22//! #[derive(Serialize, Deserialize, Clone)]
23//! struct MyData {
24//! content: String,
25//! }
26//!
27//! #[tokio::main]
28//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
29//! // Create a cache with default configuration and memory backend
30//! let backend = MemoryBackend::new();
31//! let cache = Cache::<String, MyData>::new(CacheConfig::default(), backend).await?;
32//!
33//! // Store a value
34//! cache.put("key1".to_string(), MyData { content: "Hello".to_string() }).await?;
35//!
36//! // Retrieve a value
37//! if let Some(data) = cache.get(&"key1".to_string()).await? {
38//! println!("Found: {}", data.content);
39//! }
40//!
41//! Ok(())
42//! }
43//! ```
44
45#![warn(missing_docs)]
46#![warn(rustdoc::missing_crate_level_docs)]
47
48pub mod backends;
49pub mod cache;
50pub mod config;
51pub mod entry;
52pub mod error;
53pub mod eviction;
54pub mod search;
55pub mod storage;
56
57#[cfg(feature = "metrics")]
58pub mod metrics;
59
60// Re-export main types
61pub use cache::{AsyncCache, Cache};
62pub use config::{CacheConfig, EvictionPolicy, PersistenceConfig};
63pub use entry::{CacheEntry, EntryMetadata};
64pub use error::{CacheError, Result};
65pub use search::{SearchQuery, Searchable};
66pub use storage::StorageBackend;
67
68// Re-export backend implementations
69#[cfg(feature = "filesystem-backend")]
70pub use backends::filesystem::FilesystemBackend;
71pub use backends::memory::MemoryBackend;
72
73/// Prelude module for convenient imports
74pub mod prelude {
75 pub use crate::{
76 AsyncCache, Cache, CacheConfig, CacheEntry, CacheError, EntryMetadata, Result, Searchable,
77 StorageBackend,
78 };
79
80 #[cfg(feature = "filesystem-backend")]
81 pub use crate::FilesystemBackend;
82 pub use crate::MemoryBackend;
83}