We have a suite of applications including a website, a client application and multiple windows services. All these applications work on the same dataset and use an in-memory cache. Of course, this setup fails when one of the applications does something that invalidates the cache. I'm looking for a solution that will allow me to invalidate the cache across the applications. We have some ideas, but I'm sure the collective minds of the internet can give us a better solution.

Some details:

  • this is a legacy application, which means we would like to keep the changes as non-invasive as possible
  • We're hesitant to introduce another moving piece to the solution. So using an external cache is out.

Well, I think you are going to have to add a 'moving piece' here, if you want a new kind of motion :).

It seems to me that you are going to have to implement some kind of messaging between the applications to tell them to invalidate (part of) their cache.

It isn't clear in the question whether the whole cache becomes invalid for some reason, of if (much more common) a subset of the cache is becoming invalid.

In either case, there are a bunch of options on how to implement messaging. You have to consider which is simpler, the messaging or an external cache. I think most people would agree that the external cache is a better solution than attempting to maintain concurrency among various overlapping caches.

One last thought, you can also dodge this bullet if you can accept incorrect answers from the cache for certain periods of time. For example, if each app reloaded 1/5th of its cache every minute, the worst-case scenario would be that a key changes immediately after it was reloaded. Then for the next 5 minutes, that key is wrong, but, it will get reloaded after 5 minutes and assume the correct value.

  • With moving part I meant an external cache or something. Messaging between the applications seems the most likely candidate thus far. Having an invalid cache for too long a period is what we're trying to avoid. – Lodewijk Apr 23 '13 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.