My code is as below:
[HttpGet]
[OutputCache(Duration = 90, VaryByParam = "cityCode")]
public ActionResult About(string userName, string cityCode)
{
//do something...
return View();
}
- the cache works fine when I access the URL:
http://localhost:52121/LabOne/MvcCache/About?userName=admin&cityCode=010
- but when I access this route URL as below, the cache does not work, why?
I copied your code and I tested it on my machine and I configured the RouteConfig as the following
And I faced the same problem, I will explain this :
The
OutputCache
is depending on the URL, and the examples you provides is really two different URLs, although they are will make the same result.So try to request the URL http://localhost:52121/LabOne/MvcCache/About/admin/010 one more time. and you will see that
OutputCache
is working, and the MVC will bring the result from cache, because theOutputCache
has been cached this URL on previous time.UPDATE
according to this question Using outputcache in MVC and its accepted answer, the Caching are working with the URL and has no relevance with the MVC Routing System.