Performant cache structure to save duplicate calculations
Rubyist love the DRY moto (Don’t Repeat Yourself). Here’s how to implement a cache structure so that we Don’t Calculate Twice.
What we want:
- Don’t compute anything twice, until there is a good reason to think the result might change
- Any change in the database should be immediatly visible to users (no caching for a few minutes, hoping things won’t change too fast)
- Don’t compute anything that has not be requested by a user (i.e. don’t pre-calculate everything )
Sounds awesome, how do we proceed ?