Cache question

  • Thread starter Thread starter Alvin K
  • Start date Start date
A

Alvin K

Via the -global.asax- file, on application startup,

the following code does not work:

System.Web.Caching.Cache.Insert (works on all other pages ...)

whereas this works fine:

HttpContext.Current.Cache.Insert

Can anyone explain why this is so?
 
On application start there is no automatically mapped reference to the
current Cache object.

The object is handled through the HttpContext.Current.

When you reference the Cache object (or session or application) on a page,
you are in the HttpContext.Current by default.

You will have to reference the Cache object through the HttpContext.Current
outside of a direct request for a page. That goes for a web control library
or anything else outside a page request.

I have even had trouble with it when I created two threads in the same web
request.

bill
 
Back
Top