简体   繁体   中英

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.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM