Question

I have a single .NET web app running in an ARR cluster (IIS) with multiple machines.

Each machine must keep a cache for user access permissions in memory. That is, when the app must determine whether the user has permission to access a resource, it queries a memory cache to avoid database access (there's a lot of queries per user request).

The problem is that, in certain situations, this cache must be invalidated. But, as there are multiple machines, when one decides the cache must be invalidated, it has to be propagated to the other machines.

What is the best practice to solve this problem? We have an ASP.NET MVC 3 app running on a IIS ARR cluster.

Was it helpful?

Solution

Message queues are the normal solution.

You can have a queue that is subscribed by all your nodes and when you need invalidate a cache you send a message to the queue - the other nodes see this message and invalidate their queues.

MSMQ is the Microsoft message queue, but there are many third party ones. You may want to take a look at nServiceBus as an alternative.

OTHER TIPS

Invalidate all cache related to permissions, or only relevant parts of the cache (ex particular user, particular role etc?)

Anyway, I'm thinking along the lines of some pub/sub pattern, ex http://redis.io/topics/pubsub - a server that the apps subscribe to (sub), and the apps can request invalidation of cache by publishing a request to all subscribers (pub)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top