DEV Community

Discussion on: Preventing Useless Database Hits

Collapse
 
pyemkey profile image
Michał Kłoda

@molly I've watched your speech 2 days ago. Great stuff!

Collapse
 
pyemkey profile image
Michał Kłoda

@molly do you have any resources about caching strategies? What approach did you use for cache invalidation?

Collapse
 
molly profile image
Molly Struve (she/her)

Shoot, I some how totally missed this comment last month! Sorry for the late reply!

I don't really have any good resources to share since most of what we learned was through trial and error on the job. This is a big reason why I wanted to share our experiences so hopefully others can learn from them. Redis docs are also super awesome!

As for cache invalidation, that is always tricky. You really have to do what works best for your situation and use case. You want it short enough that basically no one really notices its cached, yet long enough to provide performance benefit. For somethings a 5 minute cache gives us huge gains while other caches have to be set for 24 hours to see any benefit. Take your best guess at what you think is a good number and then track your performance. Is it helping? How much is it helping? Is it noticeable at all to clients or customers? You will likely have to tweak your original guess but eventually you will find the sweet spot. We have had to tweak more than one invalidation timeframe getting to where we are now and I suspect we will be tweaking many more in the future.