Replace in-memory TTL cache with Redis for SMART data caching #1
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The current in-memory TTL cache for SMART data has several limitations:
/api/overviewresponse, which shells out tosmartctl78 times sequentiallyProposed Solution
Replace
services/cache.pywith a Redis-backed cache usingredis.asyncio.Architecture
Implementation Details
1. Redis connection (
services/redis.py)2. Cache keys and TTLs
jbod:smart:{device}SMART_CACHE_TTL)jbod:enclosuresjbod:overviewjbod:zfs_map3. Background pre-warm task
This means the API endpoints become pure Redis reads — sub-millisecond response times regardless of drive count.
4. Graceful degradation
smartctlcalls (log a warning)X-Cache: HIT/X-Cache: MISSresponse headers for debugging5. Docker changes
Add Redis as a sidecar in
docker-compose.yml(or point to existing homelab Redis):6. Dependencies
Add to
requirements.txt:Benefits
redis-cli KEYS "jbod:*"to inspect cache state, TTLs, etc.Acceptance Criteria
/api/overviewreads from Redis, responds in <50ms for 78 drivessmartctlwhen Redis is downX-Cacheresponse header on all/api/drives/*and/api/overviewendpoints