Module cache

Module cache 

Source
Expand description

In-Memory Caching Layer

Provides high-performance in-memory caching for frequently accessed data.

§Overview

The cache layer reduces database load by storing frequently accessed items in memory:

  • Workflow definitions - Most frequently accessed, rarely change
  • User quotas - Hot path for execution checks
  • API keys - Validated on every request
  • Secrets - Decrypted values cached after first access

§Cache Strategy

  • LRU Eviction: Least recently used items evicted when capacity reached
  • TTL Support: Time-based expiration for cache entries
  • Automatic Invalidation: Write-through invalidation on updates
  • Warm-up: Pre-populate cache with critical data on startup

§Usage Example

use oxify_storage::{Cache, CacheConfig};
use std::time::Duration;

let config = CacheConfig {
    max_size: 1000,
    default_ttl: Duration::from_secs(300), // 5 minutes
};
let cache = Cache::new(config);

// Store workflow in cache
cache.put_workflow(workflow_id, workflow.clone());

// Retrieve from cache
if let Some(workflow) = cache.get_workflow(&workflow_id) {
    return Ok(workflow);
}

// Cache miss - fetch from database
let workflow = fetch_from_db(&workflow_id).await?;
cache.put_workflow(workflow_id, workflow.clone());

Structs§

Cache
Multi-level cache for different data types
CacheConfig
Cache configuration
CacheMetrics
Cache metrics for monitoring
CacheStats
Cache statistics
UserQuota
WorkflowQuota