Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing OutputCache based on URL

I have got page which I would like to cache using the OutputCache directive. However, I am using a URL rewriter module to direct multiple URLs at this page, each with different contents.

Is there any way to use the cache the output for each URL? There are no other criteria by which I need to vary the cache results.

like image 535
Blatfrig Avatar asked Nov 24 '09 16:11

Blatfrig


1 Answers

In the end this was quite simple to fix.

  1. Add the following directive to the page that needs to be cached:

    < %@ outputcache duration="600" location="Downstream" varybyparam="none" varybycustom="RawURL" %>

  2. Add this method to the global.asax file

    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        switch (custom.ToUpper())
        {
            case "RAWURL":
                return context.Request.RawUrl;
    
            default:
                return "";
        }
    }
    
like image 174
Blatfrig Avatar answered Nov 15 '22 16:11

Blatfrig