I am using OutputCache in MVC 5 to cache views on a server.
I only want to cache the view based on two parameters in the query string.
Action method
[HttpGet] [OutputCache(Location = OutputCacheLocation.Server, Duration = 60*10, VaryByParam = "id;quoteid")] public ActionResult MyAction(int id, ProductCategoryType category) { return Content(DateTime.Now.ToString()); }
Route
context.MapRoute( "MyCustomRoute", "myarea/{controller}/{action}/{id}/{category}/{name}/{quoteId}", new { controller = "MyController", name = UrlParameter.Optional, quoteId = UrlParameter.Optional }, new[] { "MyNamespace.Areas.MyArea.Controllers" });
URL
http://localhost:17191/myarea/mycontroller/myaction/2/1/a-holiday/aquoteid
This works, but correctly binds the data , however, if I change any part of the {name} URL, it still generates a new cache element, although in my action method I have VaryByParam="id;quoteid"
For instance...
http://localhost:17191/myarea/mycontroller/myaction/2/1/a-holiday/somequoteid
and
http://localhost:17191/myarea/mycontroller/myaction/2/1/another-holiday/somequoteid
... generate different DateTime outputs, but they shouldn't - they should be identical.
What have I done wrong and how can I achieve the desired behavior?
Edit
To be clear, ProductCategoryType is the Enum associated with an int value. The binding for this is correct when I debug an ActionResult
Edit 2 Since I was asked to show ProductCategoryType , I added it below. It truly ties together when I debug it - I don't think it has anything to do with the problem.
public enum ProductCategoryType { TourActivity = 1, Accommodation = 2, BusPass = 3, SelfDrive = 4, }
Edit 3
URL change: http://localhost:17191/a/products/view/2/1?name=test1"eid=123
And now the cache works as expected, but how can I achieve this with a prettier URL through routing?