Files
mytheclipse/crates/mytheclipse-cache
asepharyana 8106f8943e feat: add 4 new crates (queue, tracing, http, cli) + enhancements to existing crates
New crates:
- mytheclipse-queue: unified job queue with WorkerPool, retry/backoff, DLQ
  Backends: in-memory (default), Redis, NATS, PostgreSQL
- mytheclipse-tracing: tracing subscriber layers with env filter + OTLP/Jaeger export
- mytheclipse-http: HTTP client/server with timeout + tracing, axum server
- mytheclipse-cli: CLI framework with clap derive, built-in subcommands

Enhancements to existing crates:
- mytheclipse-core: SemaphorePool, LeaderElection, HealthRegistry/HealthCheck
- mytheclipse-cache: AutoRefreshCache (bg refresh on miss), CacheMetrics
- mytheclipse-config: ConfigSchema for JSON Schema generation
- mytheclipse-storage: MultipartUploadDriver trait
- mytheclipse-crypto: PASETO v4.local token support

All features compile with --all-features; tests + clippy pass clean.
2026-08-29 16:05:02 +07:00
..

mytheclipse-cache

A unified multi-layer cache abstraction so your app isn't locked to one cache provider. Combines an in-process L1 cache with a distributed L2 cache (e.g. Redis/Valkey) behind one simple get/set/invalidate API, plus a cache-aside / auto-refresh helper.

Features

  • l1-memory (default) — zero-dependency in-process cache.
  • l1-moka — high-performance Moka-backed L1 with TTL/max-capacity.
  • l2-redis — Redis/Valkey L2 via fred.
  • cache-aside (default) — read-through cache-aside helper.

Usage

use mytheclipse_cache::{Cache, MemoryCache, MultiLayerCache, CacheAside};

let cache = MultiLayerCache::new(
    MemoryCache::new(),          // L1
    MemoryCache::new(),          // L2 (use RedisCache in production)
);
cache.set("k", b"v".to_vec(), None).await.unwrap();
let v = cache.get("k").await.unwrap();

// Cache-aside: fill misses from a source of truth.
let aside = CacheAside::new(
    MemoryCache::new(),
    |key| async move { Some(format!("data-for-{key}").into_bytes()) },
);
let _ = aside.get("orders:42").await.unwrap();