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
AI runs 70% of my distribution. The exact stack. User Avatar 160 comments I'm a solo founder. It took me 9 months and at least 3 stack rewrites to ship my SaaS. User Avatar 139 comments I built a URL indexing SaaS in 40 days — here's the honest story User Avatar 58 comments We could see our AI bill, but not explain it — so I built AiKey User Avatar 25 comments AI coding should not turn software development into a black box User Avatar 22 comments I used $30,983 of AI tokens last month in Claude code on $200/mo plan User Avatar 20 comments