Just wondering how you guys manage your cache invalidations. Given that there might objects (hundreds and thousands) in the cache that might be triggered by different algorithms or rules. How do you keep track of it all?
Is there anyway you can reference the relationships from a table in the database and enforce it somehow?
Do bear with me as I've never done any caching before.
Cache invalidation describes the process of actively invalidating stale cache entries when data in the source of truth mutates. If a cache invalidation gets mishandled, it can indefinitely leave inconsistent values in the cache that are different from what's in the source of truth.
Cache invalidation is hard because: Everything in life we want to know, changes. Those changes are non-deterministic.
The purpose of your cache layer should be pretty much that : reflecting the corresponding data in your database, but providing it faster than the database would, or at least providing it without keeping the database busy.
To achieve this, you have two solutions :
The first is pretty rare, but pretty easy to deal with : just update your cache on a regular basis.
The second point is what you'll most likely deal with in your projects : just update your cache when your database is updated. It's simpler than you'd think :
If your code is clean enough, it should be easy to implement an efficient cache policy on top of it. There's a little more about caching and how to do it well in that answer I posted some times ago. Hopefully this all will help you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With