如何与QUOT;无效:QUOT; ASP.NET MVC输出缓存的部分? [英] How to "invalidate" portions of ASP.NET MVC output cache?
问题描述
有没有一种方法以编程方式无效ASP.NET MVC输出缓存的部分?我希望能够做的是,如果改变什么会从缓存动作返回用户帖子的数据,能够无效的缓存数据。
Is there a way to programmatically invalidate portions of the ASP.NET MVC output cache? What I would like to be able to do is, if a user posts data that changes what would be returned from a cached action, be able to invalidate that cached data.
这甚至可能吗?
推荐答案
的一种方法是使用的方法:
One way is to use the method :
HttpResponse.RemoveOutputCacheItem("/Home/About");
在这里描述的另一种方法: http://aspalliance.com/668
我想你可以通过使用你想要的每一个动作的方法级属性实现第二种方法,只是添加到它的字符串重新presenting的关键。这就是,如果我理解你的问题。
I think you could implement the second method by using a method level attribute for every action that you want and just add to it the string representing the key. That's if I understood your question.
编辑:是在asp.net MVC的OutputCache只是一个包装
Yes the asp.net mvc OutputCache is just a wrapper .
如果你使用的VaryByParam =无
,那么你只无效/统计
- 那就是如果<&ID1 GT; /<&ID2 GT;
的查询字符串值。这将无效页面的所有版本。
If you're using varyByParam="none"
then you just invalidate "/Statistics"
- that's if <id1>/<id2>
are querystring values. This will invalidate all versions of the page.
我做了一个快速测试,如果您添加的VaryByParam =ID1
,然后创建页面的多个版本 - 如果你说无效无效 /统计/ ID1
将失效只是该版本。但是,你应该做进一步的检查。
I did a quick test and if you add varyByParam="id1"
and then create multiple versions of the page - if you say invalidate invalidate "/Statistics/id1"
it will invalidate just that version. But you should do further tests.
这篇关于如何与QUOT;无效:QUOT; ASP.NET MVC输出缓存的部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!