2

Normally we can do caching and make dependency on Request.QueryString values like

<%@ OutputCache Duration="15" VaryByParam="search" %>

The url for such may be like:

http://www.demo.com/default.aspx?search=name

But in my application i am using ASP.NET 4.0 routing where i am passing the id of a product like:

 http://www.demo.com/searchdetails/40563

or

http://www.demo.com/searchdetails/40564

and so on.....

In this case i access the product id something as

 Page.Route.Value["product_id"]

In this case how should i make the dependency of page on this route value.

I am new to caching so i dont have any much knowledge of the same.

Do we need to do some custom caching.

John Saunders
  • 160,644
  • 26
  • 247
  • 397

1 Answers1

2

I think you have to use VaryByCustom. Something like this:

<%@ OutputCache Duration="15" VaryByParam="None" VaryByCustom="productIdInUrl" %>

And then add your custom filter to the global.asax file:

public override string GetVaryByCustomString(HttpContext context, 
string arg)
{
   if(arg == "productIdInUrl")
   {
      return context.Request.RawUrl;
   }
   return base.GetVaryByCustomString(context, arg);
}

This would vary on all of your URL, not just the productId. I guess you could do some more work on the Request object to do something more clever if needed

Olav Nybø
  • 11,454
  • 8
  • 42
  • 34