MVC 5中的"CacheProfile"

Ser*_*rge 7 .net asp.net-mvc caching outputcache asp.net-mvc-5

我是MVC的初学者,我有一个项目,从MVC2转换到最新版本的MVC.我读了一些关于MVC 4的书,所以我开始理解主要的机制.

但是,在转换我的MVC 2解决方案时,我遇到了一个属性问题:OutputCache.

通过例如.我有多个这样的动作(属性可能会有所不同):

[OutputCache(CacheProfile = "ProductImage")]
public ActionResult GetImage(Guid elementId, int imgtype)
Run Code Online (Sandbox Code Playgroud)

在Web.Config我有"缓存> outputCacheSettings> outputCacheProfiles>":

<add name="ProductImage" duration="5" varyByParam="elementId,imgtype" />
Run Code Online (Sandbox Code Playgroud)

并在输出中获取以下异常:

子操作的OutputCacheAttribute仅支持Duration,VaryByCustom和VaryByParam值.请不要为子操作设置CacheProfile,Location,NoStore,SqlDependency,VaryByContentEncoding或VaryByHeader值.

据我所知,问题只出现在儿童行动中.

  • 还有另一种方法可以在最新的MVC中使用缓存配置文件吗?
  • 有没有办法确定该动作是否为子动作才能修改该动作?

Ser*_*rge 5

解决了安装MvcDonutCaching nuget 并替换[OutputCache[DonutOutputCache...

查看更多关于。