.NET Web Caching

  • Thread starter Thread starter Tim
  • Start date Start date
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
 
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.
 
Back
Top