armature-cache
Cache management for the Armature framework.
Features
- Multiple backends — Redis (
RedisCache), in-memory (InMemoryCache), and optional Memcached (MemcachedCache, behind thememcachedfeature) - TTL support — per-entry expiration, plus a configurable default TTL
- Async API — non-blocking cache operations via the
CacheStoretrait - JSON values — the store works with JSON string payloads (
get_json/set_json) - Batch primitives —
get_many/set_many/delete_many, backed by nativeMGET/MSET/DELon Redis - Multi-tier caching —
TieredCache(L1 in-memory + L2 distributed) with live hit/miss/promotion stats - Tag-based invalidation —
TaggedCacheinvalidates groups of keys by tag
Installation
[]
= "0.1"
The redis backend is enabled by default. Enable Memcached explicitly:
[]
= { = "0.1", = ["memcached"] }
Quick Start (Redis)
use ;
use Duration;
async
connection_timeout, operation_timeout, and max_connections are applied to
the Redis connection manager. An operation that exceeds operation_timeout
fails with CacheError::Timeout.
In-Memory Cache
InMemoryCache implements the same CacheStore trait and is handy for tests or
as the L1 tier. It is bounded (default DEFAULT_MAX_ENTRIES) and evicts expired
entries lazily on read and eagerly when making room:
use ;
# async
Multi-Tier Caching
use ;
use Arc;
# async
Tag-Based Invalidation
use ;
use Arc;
# async
The tag index is persisted in the backing CacheStore itself (not a local,
per-process map), so it is visible across every instance sharing that store.
Only backends that override CacheStore::set_add/set_remove/set_members
with a native set type (RedisCache, via SADD/SREM/SMEMBERS) update it
atomically; other backends fall back to a non-atomic read-modify-write, which
can race under concurrent tagging of the same tag from different instances.
Memcached (requires the memcached feature)
use ;
let config = memcached?;
let cache = new.await?;
cache.set_json.await?;
Note: the memcached protocol exposes no way to read an item's remaining TTL, so
MemcachedCache::ttl always returns Ok(None).
License
MIT OR Apache-2.0