Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

outputcache with ajax

Status
Not open for further replies.

darylbewise

Programmer
Jan 5, 2009
16
GB
Hello All,

I am adding output cache to a few usercontrols within my website that have quite a few database calls.

I have added the following into the uc:
Code:
<%@ OutputCache Duration="100000" VaryByParam="none"%>

All works fine with the caching, except when I come to click a button that will sort the details within the user control by a different variable.

Is there any way of implementing the output cache on the standard data (that everyone will see when they visit the page), but remove the output cache once the user decides to sort by a different variable?

Cheers
 
2 options:
1. cache the data, not the rendered output. it's the db calls that are "expensive", not rendering the view.
2. define a default sort and use the default sort value as an outputcache parameter.

the simplest way to implement #1 is to load the data into the asp.net cache collection.
Code:
var data = Cache["key"] as object[];
if(data == null)
{
   data = GetDataFromDatabase();
   Cache["key"] = data;
}
return data;
however, you also need to manage how to handle stale object state. This can quickly become a very complex issue. depending on how you access the database the framework may have some options/extension point built in. for eaxmple NHibernate and ActiveRecord allow you to configure caching through a variety of caching frameworks.

option 2 may be easier to implement given your application architecture. You could implemnt VarByCustom and override the GetCustomCacheKey (or something like that) in the global.asax file. for more information on this approach google "asp.net custom output cache".

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top