0

I have a complex website that uses .NETs output caching enabled through Sitefinity. Recently we needed to have a specific user control have different cached versions depending on user location. So I gave the user control an OutputCache directive with VaryByCustom set and overrode the GetVaryByCustomString method in Global.asax to get the user location. The problem is that even in a simple test case this is not working. We tested this use case outside the context of Sitefinity to verify whether it was causing the issue by making a new project containing an .aspx page and placing a new .ascx user control inside of it. The page has a label that gets the current time on load as well as the control. The control also has a label that renders the current time. If I give the page OutputCache set to this:

<%@ OutputCache Duration="60" VaryByParam="none" %>

and the control set to this:

<%@ OutputCache Duration="60" VaryByParam="none" VaryByCustom="browser" %>

the expected functionality does not happen. The thinking was that if we opened this page in two different browsers we would see two different times in the second label. Am I completely missing something here? I am new to dealing with .NET caching so it is entirely possible.

Thanks

Here is my override of GetVaryByCustomString:

    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        if (custom == "custom")
        {
            // return custom logic
        }
        else
        {
            return base.GetVaryByCustomString(context, custom);
        }
    }
Tim
  • 1,029
  • 7
  • 20
rpf3
  • 651
  • 1
  • 10
  • 21

1 Answers1

0

If you are using

  <%@ OutputCache Duration="60" VaryByParam="none" VaryByCustom="browser" %>

Then the cache should be different for each browser with a different major version + browser type. So Firefox 3.5.0 and Firefox 3.6.0 should see the same but Firefox 3.5 and firefox 2.0 should see different.

I assume you have not accidentally overloaded HttpApplication.GetVaryByCustomString in global.asmx to handle the browser instead of allowing .NET to do it?

John Mitchell
  • 9,653
  • 9
  • 57
  • 91
  • no, the only thing I had in the overload was checking if it was our custom value, otherwise I returned control to the base method – rpf3 Jun 16 '12 at 01:21