Crate skp_cache

Crate skp_cache 

Source
Expand description

skp-cache: Advanced, modular caching library for Rust

§Features

  • Multi-tier caching (L1 Memory + L2 Redis)
  • Dependency graph-based invalidation
  • Pluggable serialization (JSON, MessagePack, Bincode)
  • Metrics integration
  • Stampede protection

§Quick Start

use skp_cache::prelude::*;

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    let backend = MemoryBackend::new(MemoryConfig::default());
    let cache = CacheManager::new(backend);

    cache.set("key", &42i32, CacheOpts::new().ttl_secs(60)).await?;
     
    match cache.get::<i32>("key").await? {
        CacheResult::Hit(entry) => println!("Got: {}", entry.value),
        CacheResult::Miss => println!("Cache miss"),
        _ => {}
    }
     
    Ok(())
}

Modules§

prelude
Prelude for convenient imports

Structs§

CacheEntry
A cached entry with full metadata
CacheGroup
A logical grouping of cache entries with shared namespace and invalidation
CacheManager
High-level cache manager with pluggable serialization and metrics
CacheManagerConfig
Configuration for CacheManager
CacheOptions
Configuration options for a cache entry
CacheOpts
Builder for CacheOptions with fluent API
CacheStats
Statistics for cache operations
CompositeKey
Composite key builder for complex keys
JsonSerializer
JSON serializer (default)
MemoryBackend
In-memory cache backend
MemoryConfig
Configuration for the memory backend
NoopCompressor
No-op compressor (disabled compression)
NoopMetrics
No-op metrics implementation (default)
ReadThroughCache
A cache wrapper that automatically loads data on miss

Enums§

CacheError
Main error type for all cache operations
CacheOperation
Cache operation for latency tracking
CacheResult
Result of a cache lookup operation
CacheTier
Cache tier for metrics labeling
EvictionReason
Reason for cache eviction

Traits§

CacheBackend
Core trait for all cache storage backends
CacheKey
Trait for types that can be used as cache keys
CacheManagerReadThroughExt
CacheMetrics
Trait for cache metrics/observability
Compressor
Trait for compression implementations
DependencyBackend
Extended trait for backends that support dependency tracking
DistributedBackend
Extended trait for distributed backends
Loader
Trait for automatic data loading on cache miss
Serializer
Trait for pluggable serialization formats
TaggableBackend
Extended trait for backends that support tag-based operations

Type Aliases§

Result
Result type alias for cache operations