Files
mytheclipse/crates/mytheclipse-cache
asepharyana db4f277336 feat: add corex-storage crate for unified storage abstraction
- Introduced corex-storage crate with support for local disk, S3-compatible, and Google Cloud Storage backends.
- Implemented StorageDriver trait for various storage backends.
- Added LocalFileStorage for local disk operations.
- Added S3Storage for S3-compatible object storage with multipart upload support.
- Added GcsStorage for Google Cloud Storage operations.
- Included error handling for storage operations.
- Added tests for each storage backend to ensure functionality.
- Created README.md for documentation and usage examples.
- Added Apache and MIT licenses for open-source compliance.
2026-08-28 22:24:18 +07:00
..

corex-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 corex_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();