Skip to main content

Crate threatflux_cache

Crate threatflux_cache 

Source
Expand description

§ThreatFlux Cache

A flexible async cache library for Rust with pluggable backends and serialization.

§Features

  • Async-first: Built on tokio for high-performance async operations
  • Generic: Works with any serializable key-value types
  • Pluggable backends: Filesystem, memory, or custom implementations
  • Flexible serialization: JSON, bincode, or custom formats
  • Eviction policies: LRU, LFU, FIFO, TTL-based eviction
  • Compression: Optional compression for stored values
  • Search capabilities: Query cache entries with custom predicates
  • Metrics: Optional Prometheus metrics integration

§Quick Start

use threatflux_cache::{Cache, CacheConfig, MemoryBackend, AsyncCache};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Clone)]
struct MyData {
    content: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a cache with default configuration and memory backend
    let backend = MemoryBackend::new();
    let cache = Cache::<String, MyData>::new(CacheConfig::default(), backend).await?;
     
    // Store a value
    cache.put("key1".to_string(), MyData { content: "Hello".to_string() }).await?;
     
    // Retrieve a value
    if let Some(data) = cache.get(&"key1".to_string()).await? {
        println!("Found: {}", data.content);
    }
     
    Ok(())
}

Re-exports§

pub use cache::AsyncCache;
pub use cache::Cache;
pub use config::CacheConfig;
pub use config::EvictionPolicy;
pub use config::PersistenceConfig;
pub use entry::CacheEntry;
pub use entry::EntryMetadata;
pub use error::CacheError;
pub use error::Result;
pub use search::SearchQuery;
pub use search::Searchable;
pub use storage::StorageBackend;
pub use backends::filesystem::FilesystemBackend;
pub use backends::memory::MemoryBackend;

Modules§

backends
Storage backend implementations
cache
Core cache implementation
config
Configuration types for the cache
entry
Cache entry types and metadata traits
error
Error types for the cache library
eviction
Eviction strategies for cache entries
prelude
Prelude module for convenient imports
search
Search and query functionality for cache entries
storage
Storage backend trait and utilities