Accessing Cache from Custom Web Server Control

  • Thread starter Thread starter Jordan S.
  • Start date Start date
J

Jordan S.

In a "standard" aspx page I can access the system cache
(System.Web.Caching.Cache), like this:
Cache["SomeObject"] = someObject;

How can I access the same Cache from *within* a custom composite Web server
control I'm writing (that lives in it's own assembly) that is dynamically
added to a page at runtime? What do I need to do with the custom control or
it's containing assembly to enable it to access the Cache of the hosting Web
application?

Thanks.
 
Hello Jordan S.
How can I access the same Cache from *within* a custom composite Web
server control I'm writing (that lives in it's own assembly) that is
dynamically added to a page at runtime? What do I need to do with the
custom control or it's containing assembly to enable it to access the
Cache of the hosting Web application?
Two Ways:

HttpContext.Current.Cache

this.Page.Cache

both gives the same Reference to the current Cache Object.
 
Peter Bucher said:
Hello Jordan S.

Two Ways:

HttpContext.Current.Cache

this.Page.Cache

both gives the same Reference to the current Cache Object.



Unfortunately neither of your suggestions works in my case. I want to access
the Cache from *within* a web server control. There is no "this.Page"
reference in a web server control.

The suggestion for HttpContext.Current.Cache seems promising, but it's
currently not available in my control's class.

Am I just missing some reference? The project/assembly within which my
control exists references System.Web. What else do I need to reference - or
what do I need to do to be able to access teh current context from within a
custom control?

Thanks.
 
Your just missing a reference. HttpContext.Current.Cache is the same
object. You can also use HttpRuntime.Cache. Little less overhead when
using this one.

I believe they are in System.Web
-joe
 
Got it... I was referencing System.Web... but was missing the using
statement.... (Doh!....)

Thanks.



Your just missing a reference. HttpContext.Current.Cache is the same
object. You can also use HttpRuntime.Cache. Little less overhead when
using this one.

I believe they are in System.Web
-joe
 
Back
Top