Search code examples
asp.net-mvc-3outputcache

Applying multiple attributes for the OutputCache


i have the following search action method, currently i am applying the cache to only one search parameter which is causing some false results incase the user change the q2 or q3 parameters while keeping the same value for the q paramter so the search result will return the same search results regardless of the q2 and q3 values, so i need to apply the cache for the three search parameters together,, so how i can do so?

[OutputCache(CacheProfile = "long", VaryByParam = "q")]
        public PartialViewResult Search(string q, int q2,string q3,string sortOrder)
        {

Solution

  • [OutputCache(CacheProfile = "long", VaryByParam = "q;q2;q3")]
    

    Use a semicolon-separated list for your parameters.

    OutputCacheAttribute.VaryByParam Property MSDN Reference