GER
GER

Reputation: 2032

Scope of HttpContext.Current.Cache

If I have the following line in multiple websites that run on the same server will there be any problems with the app's writing to the same cache record?

HttpContext.Current.Cache["SearchResults"] = myDataTable;

I know the docs say there is one cache per app domain but I don't quite understand what that means.

https://msdn.microsoft.com/en-us/library/system.web.httpcontext.cache There is one instance of the Cache class per application domain. As a result, the Cache object that is returned by the Cache property is the Cache object for all requests in the application domain.

Upvotes: 0

Views: 1362

Answers (1)

Arindam Nayak
Arindam Nayak

Reputation: 7462

Application domain is a mechanism (similar to a process in an operating system) used within the Common Language Infrastructure (CLI) to isolate executed software applications from one another so that they do not affect each other.

So when you write to cache, it will be stored in memory for that app domain and if you have web garden ( which has multiple worker process) or web farm, then request might be served by diff worker proc/node, then those node/work proc don't have access to cache as those are entirely diff app domain.

So it states cache is specific to single app domain, to solve the above issue, you need to look for centralised cache store.

Upvotes: 1

Related Questions