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
710% Growth on my tiny productivity tool hit differently, here is what worked in January User Avatar 65 comments Write COLD DM like this and get clients easily User Avatar 31 comments I built a tool to search all my messages (Slack, LinkedIn, Gmail, etc.) in one place because I was losing my mind. User Avatar 26 comments Our clients have raised over $ 2.5 M in funding. Here’s what we actually do User Avatar 15 comments 🚀 I Built a Chrome ExtensionThat Turns Reddit Into a Real-Time Lead & Research Engine(Free for First 10 Users) User Avatar 13 comments How I got my first sale from a forgotten project User Avatar 10 comments