Chris G
Chris G

Reputation: 479

IIS App Pool And Caching

I have created a public List that is runs and is accessed from my a Web Application.

private static List<x> _x;
static readonly object lockObjx = new object();

public static void XCache()
{
            if (_x != null)
                return;

            lock (lockObjx)
            {
               _x = GetFromDatabase();
            }
}

This all runs happily under the default app pool. I now need to add a web service that can update the this cache. Will I be able to do this running on the default app pool? If not is there a way I can do this without installing something like MEMCache. The Service and and Wepp run on the same server.

Upvotes: 3

Views: 7120

Answers (2)

Jay Shah
Jay Shah

Reputation: 3771

Cache and sessions are specific to the AppDomain(NOT App Pool).

Different web applications will always have different App Domains, even if they're running under same app pool. So they will have separate cache, separate session, separate objects, separate static references, etc.

However, there's a way to share cache/objects between different applications of same app pool : Shared variable across applications within the same AppPool?

Upvotes: 1

driis
driis

Reputation: 164341

In order to make that work, you need to put the service in the same ASP .NET Application as the web application. This usually means running them in the same Site in IIS.

Each ASP .NET Application gets its own AppDomain. Each AppDomain has it's own copy of all objects, including static references. In other words, data is not shared between AppDomain's, and hence is not shared by individual applications in IIS, even if they are running in the same IIS process (AppPool).

There's a nice article here: http://odetocode.com/Articles/305.aspx. It might be a bit old, but it should still be valid.

Upvotes: 5

Related Questions