0
votes

I am building MVC application and would like to put caching in my application. I have read about caching that you need to just put [OutputCache(Duration=60, VaryByParam="none")] above controller method and it will work. However in my case i would like to cache not for whole controller methods but inner methods which would call from index controller and which will return IEnumerable<SelectListItem> and that result i want to cache.

But caching is only work for controller methods which will result view result, i have also searched for caching for non view methods and found some MVCDonutCaching and read this articles and by installing tried this also as per below

   [DonutOutputCache(Duration=60, VaryByParam="none")]
    public IEnumerable<SelectListItem> GetRegionList()
    {
        Region region = new Region();

        return region.GetRegionsList();
    }

But not luck to achieve my goal! have anyone done this type of caching here? then please help me to achieve this things.

Thanks in Advance.

1

1 Answers

1
votes

I believe your problem is not with mvc itself but with caching model data. Caching your controller action is like forming static page and saving it in IIS cache. Every time user asks for the "Home/Index" (for example), the IIS takes well-formed page (html) from cache without executing any code.

What you're trying to do is cache model data. That's quite a different thing since it has nothing to do with IIS and html page forming. You could use existing solutions like: Unity Application Block - http://msdn.microsoft.com/en-us/library/ff649102.aspx Or this post from stackexchange: https://softwareengineering.stackexchange.com/questions/35709/recommendations-for-a-net-distributed-caching-framework