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 Answer 1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.