如何“无效"ASP.NET MVC 输出缓存的一部分? [英] How to "invalidate" portions of ASP.NET MVC output cache?

查看:28
本文介绍了如何“无效"ASP.NET MVC 输出缓存的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式使 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.

这甚至可能吗?

推荐答案

一种方法是使用方法:

HttpResponse.RemoveOutputCacheItem("/Home/About");

这里描述了另一种方式:http://aspalliance.com/668

Another way is described here : http://aspalliance.com/668

我认为您可以通过为您想要的每个操作使用方法级别属性来实现第二种方法,只需向其中添加表示键的字符串.如果我理解你的问题的话.

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="none" 那么您只会使 "/Statistics" 无效 - 如果 <id1>/<id2> 是查询字符串值.这将使页面的所有版本无效.

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" 然后创建页面的多个版本 - 如果你说 invalidate invalidate "/Statistics/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.

这篇关于如何“无效"ASP.NET MVC 输出缓存的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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