I’ve got an app that implements a command object pattern to get data from a server. Now I’d like to implement a client side cache and I need some pointers on how to deal with cache eviction invalidating.
The problem
To get an object I pass the GetObject(id) command and receieve a GetObjectResponse with the results for that id. I’ve got a cache going that can cache the response for GetObject(id) nicely.
However, when I see a command like DeleteObject(id) or UpdateObject(id), the cached response for GetObject(id) needs to be invalidated.
I should say that the reality is not necessarily this simple as with a single id parameter. Some response objects depend on more than one parameter in the command object. Also, passing one command object could invalidate more than one response objects.
Any thoughts on how to accomplish this? Thanks in advance!
I ended up writing a CacheInvalidationGenerator class with this method:
The method simply returns action objects to be invalidated from the cache. Of course, these can also generate invalidations, so this method should be called recursively.