5
0 Comments

Use Redis Sets to track and expire cache keys in Rails

Doing efficient backend caching (queries/models) usually requires having a properly organised expiration strategy. Most of the time it means having smart callbacks on models to expire cache keys when models get updated.

The problem with this approach is that you quickly end up cluttering your models with custom callbacks not providing real business value to your app logic.

The article below presents a reusable approach which uses Redis Sets to register cache keys that must be expired on model update. The approach is declarative, meaning that each cache entry declares which models it depends on. The logic can easily be encapsulated in a module for reusability.

https://www.keypup.io/blog/use-redis-sets-to-track-and-expire-cache-keys-in-rails

You use a different approach to track and expire cache keys? Feel free to share!

posted to Icon for group Ruby on Rails
Ruby on Rails
on March 9, 2021
Trending on Indie Hackers
Stop Spamming Reddit for MRR. It’s Killing Your Brand (You need Claude Code for BuildInPublic instead) User Avatar 218 comments What happened after my AI contract tool post got 70+ comments User Avatar 212 comments Where is your revenue quietly disappearing? User Avatar 86 comments $36K in 7 days: Why distribution beats product (early on) User Avatar 82 comments We made Android 10x faster. Now, we’re doing it for the Web. 🚀 User Avatar 71 comments a16z says "these startups don't exist yet - it's your time to build." I've been building one. User Avatar 56 comments