Accessing Cache from Custom Web Server Control

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.
 
P

Peter Bucher [MVP]

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.
 
J

Jordan S.

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.
 
J

Joe

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
 
J

Jordan S.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top