Handling Multiple Caches in App
Article Summary
Swiggy's mobile team faced a common problem: juggling disk caches, LRU caches, and databases without creating a maintenance nightmare. Here's their elegant solution.
Ravi Gupta from Swiggy's engineering team shares their architecture for managing multiple caching mechanisms (disk, LRU, database) across different asset types like images, Lottie animations, and videos. The approach keeps each layer independent while making it easy to add new cache types.
Key Takeaways
- Three layer architecture: Utils, Assets Manager, and Caching Layer
- Images use both disk and LRU caching simultaneously
- Animations rely on LRU, videos use custom disk cache
- Protocol driven APIs keep layers mutually exclusive and swappable
- New caching mechanisms plug in without changing existing flow
Critical Insight
A clean separation of concerns lets Swiggy mix disk caching, LRU caching, and custom solutions without tight coupling or code changes when adding new cache types.