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!