Best cache is no cache. Way too often, I see cache as the answer to your performance problems. Slow API responses due to slow queries? Just put Redis in front of the database.
Cache always comes with a price. You need to create it, maintain it, and, worst of all, invalidate it at some point.
So before you start running into Redis’s or CloudFront’s lap - check whether you really:
- pushed everything from your database with indexing, partitioning, and repacking,
- have optimized queries that are using index-only scans,
- need to store that much data
- need to access all that data
- need to access data so frequently
If there’s no other way, go for the cache. But often the problem lies elsewhere, and solving it means you don’t need to deal with the cache and its invalidation.
Stick to simplicity!