I’m in the process of making a fairly complex application. It is expected to run across multiple web servers, otherwise this would be easy.
Basically, we have a set of Client records. Each Client record has an XML column which contains all of the “real” data, such as the clients name and other fields which are made dynamically. Our users can update a client’s record at anytime. Also, we have Application records. Each application is tied to multiple clients. Each application is usually tied to more than 3 clients. Each client’s XML data is greater than 5k of text, usually.
In some profiling I’ve done, obtaining and deserializing this XML data is a fairly expensive operation. At one portion of our web application, we must have very low latencies (related). So during this portion, our web application is a JSON web service. When a request is made to it, usually, every client record will be needed(in full, due to how it’s currently coded). I’m attempting to make as few database hits as possible in this portion.
How long should I cache the Client records’ XML objects? Knowing the user can change it at anytime, I’m not sure if I should cache it at all, but can users live with slightly stale data?
Instead of refreshing the cache on any kind of schedule, just compare the last modified date of any critical records with the cached value when accessed, which should be a very inexpensive operation. Then update the cache only when needed.