We have a website that runs on two load balanced servers. We use the ASP.Net caching to help improve performance by caching high usage data. BUT, occasionally that data changes. When it does, we need to clear the relevant cache items on BOTH the load balanced servers. Does anyone have some easy to implement suggestions for how this can be done?
I know that there is software out there to manage this for you (Microsoft Velocity for one). I also know that there are other options for having separate state servers etc. However, for what we want they all seem like overkill. Just a simple mechanism for clearing out specific cache items across servers is all we need for now.
Thanks for any suggestions.
Why not define a Cache Dependancy on an object both servers can see? You could use a SQL or File cache dependancy.
Link to Caching Msdn Page
We use a simple web service approach. Our cache clear mechanism checks a web config setting to see if any other servers exist and calls the web service on those server(s) asynchronously.
We store data with specific naming convetions to make it easy to clear what we want. So we pass in either a prefix or postfix for the item to be removed as sometimes it might be user specific (ex. the userid is appended to the name of the item) or application specific (ex. the prefix of the item is the application name).
Here is a VB example of the ClearItem routine that would be called on either one of your nodes:
You can see that the code above calls other server(s) by using this helper class:
The web service on the remote server then calls the same code that the _ClearItem called.