“CacheProfile” in MVC 5

强颜欢笑 提交于 2019-12-10 12:57:42

问题


I am beginner in MVC and I have a project to transform from MVC2 to the latest version of MVC. I read read some books on MVC 4, so I started to understand the main mechanisms.

However, when transforming my MVC 2 solution, I have a problem with an attribute: OutputCache.

By eg. I have multiple Actions like this (the attributes may vary):

[OutputCache(CacheProfile = "ProductImage")]
public ActionResult GetImage(Guid elementId, int imgtype)

in the Web.Config i have in the "caching>outputCacheSettings>outputCacheProfiles>":

<add name="ProductImage" duration="5" varyByParam="elementId,imgtype" />

and obtaining the following exception in output:

OutputCacheAttribute for child actions only supports Duration, VaryByCustom, and VaryByParam values. Please do not set CacheProfile, Location, NoStore, SqlDependency, VaryByContentEncoding, or VaryByHeader values for child actions.

As I understood, the problem appears only with the child actions.

  • Is there another way to have a cache profile in the latest MVC?
  • Is there a way to identify if the action is a child one in order to modify just that action?

回答1:


Resolved installing MvcDonutCaching nuget and replacing [OutputCache with [DonutOutputCache...

See more about.




回答2:


Please read the answer this question, I believe it answers your question pretty well.



来源:https://stackoverflow.com/questions/21829479/cacheprofile-in-mvc-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!