.NET Web Caching

T

Tim

I'm building a .NET C# web application using web caching.
The Cache class only works when I'm using an aspx page. I
want this Caching logic to be in its own class file (.cs)
in another project so other developers can use it too.
I'm instaintiating the Cache class like this but the
methods do not work like this.

Cache webCache = new Cache();
webCache.Add(.......)

Does web caching have to happen in aspx pages only?

-Tim
 
K

Kevin Spencer

First of all, Tim, you don't want to create a new Cache object; it already
exists in the Application. When you reference an object from the HttpContext
of a Page from a class that doesn't derive from Page, you can grab it from
the HttpContext under which the class operates (which is from inside a
Page). Example:

System.Web.Caching.Cache myCache = System.Web.HttpContext.Current.Cache;
myCache.Add(...);

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 

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

Top