When to cache in your Rails app
mikecoutermarsh.com
mikecoutermarsh.com
>4. Database queries can probably be left uncached
...but maybe I am thinking about it wrong. Imagine building Quora as a Rails App. For all the interesting user stats like "your answers have been viewed 28,000 times" I feel like your choice is to either denormalize in the application logic and database or cache the complex queries. Are most people taking the first approach?
What I would _not_ be doing is something like the active record cache_key to calculate if any changes have occurred to decide if you grab from redis or run the query again. For something like view count, it doesn't matter if the data is slightly stale.
Seriously if it’s in the db use an index - it’s a cache.
If you can’t get an index - background worker into a cache
There's that old joke: What are the two hardest things in computer science? Cache expiry, and naming things.