Add support for multi-layer caching (memory → Redis fallback)
Author: newmizanurCreated Oct 28, 2025Updated Jul 29, 2026
Labelsenhancement
Description
Currently, Loco supports configuring either an in-memory (Mako) cache or a Redis cache for application-level caching. However, many production environments would benefit from a multi-layer cache system — where the application checks memory first and falls back to Redis if a key is not found.
This would combine the speed of in-memory caching with the persistence and distribution benefits of Redis.
Proposed behavior
Add support for a two-layer cache chain, such that:
- The cache lookup first checks the in-memory (Mako) cache.
- If the key is not found, it falls back to Redis.
- When setting a value, it updates both layers.
Optionally, developers should be able to configure:
- TTL sync between layers.
- Whether both layers are enabled (e.g. only memory, only Redis, or both).
- Error handling if one layer is unavailable.
Example configuration
cache:
kind: Multi
layers:
- kind: Memory
max_size: 100
- kind: Redis
uri: "redis://localhost:6379"
max_size: 10Benefits
- Faster cache hits for hot keys via memory.
- Reduced Redis load.
- Persistent distributed cache for scale-out deployments.
References
- Loco cache documentation
- Inspiration: multi-tier caching in frameworks like Spring, Django, and ASP.NET.
Source: loco-rs/loco