1

I have a MVC controller action method which has a lot of functionality and that includes calling a private method. This private method calls webapi service returns response to controller action. I want to cache this output to minimize number of calls to Webapi.

I think, we don't have any attribute support (like OutputCache on action) on a normal methods of a controller. I can only think of using MemoryCache, but please share if any best way to implement Caching here.

MVC Controller Action -> private method -> Call to Webapi service

1 Answers1

1

You can use the regular System.Web.Cache, as you can see in this SO Q&A:

How to cache data in a MVC application

Be aware that Cache["key"] return a reference to the cached data. So if you recover the value from cache and modify it, the modification is automatically reflected in the cache. (This apply only to class type, not to valu types, i.e. structs or primitive types).

Community
  • 1
  • 1
JotaBe
  • 38,030
  • 8
  • 98
  • 117