I'm using the OutputCache in MVC but I'm having difficulty caching when a timestamp has been appended to the URL.
In particular jQuery's AJAX component adds _=21321423432 to the end of the url.
Everytime I call the action's URL it will always step into the action instead of returning the cached item.
I'm using the VarByCustom & VarybyParam elements to cache based on the logged in user and the start and end dates.
Action
[OutputCache(CacheProfile = "FeedCache")]
public async Task<JsonResult> Feed(DateTime start, DateTime end)
{
//Do something
return Json(result, JsonRequestBehavior.AllowGet);
}
Config
<add name="FeedCache" duration="600" varyByParam="start;end" varyByCustom="user" location="Server" />
Global.asmx
public override string GetVaryByCustomString(HttpContext context, string custom)
{
//
// Vary by logged in user
//
if (custom == "user")
{
return "user=" + context.User.Identity.Name;
}
return base.GetVaryByCustomString(context, custom);
}
I was under the impression this would cache specifically for the user & the start and end parameters however this is not the case. Is there something I'm missing?