ASP.NET MVC.如何清除[OutputCacheAttribute]缓存的值 [英] ASP.NET MVC. How to clear values cached by [OutputCacheAttribute]

查看:93
本文介绍了ASP.NET MVC.如何清除[OutputCacheAttribute]缓存的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用[OutputCacheAttribute]缓存一些操作.一切正常.假设我将其Duration属性设置为1小时.但是我希望能够清除缓存的值.有可能吗?

I use [OutputCacheAttribute] to cache some actions. Everything works fine. Let's say I set its Duration property to 1 hour. But I want to be able to clear cached values. Is it possible?

推荐答案

查看[OutputCacheAttribute]源代码后,似乎唯一可行的解​​决方案是实现一个从MemoryCache派生的新类并将其设置为OutputCacheAttribute.ChildActionCache属性.此类将为所有缓存键使用一些自定义前缀,因此我将很容易找到它们(然后从缓存中删除).

After looking at [OutputCacheAttribute] source code, it seems that the only possible solution is to implement a new class derived from MemoryCache and set it OutputCacheAttribute.ChildActionCache property. This class will be use some custom prefix for all cached keys, so I'll be quite easy to find them (and then remove from cache).

这篇关于ASP.NET MVC.如何清除[OutputCacheAttribute]缓存的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆