How to “invalidate” portions of ASP.NET MVC output cache?

后端 未结 2 2050
情话喂你
情话喂你 2020-12-07 13:16

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

2条回答
  •  自闭症患者
    2020-12-07 14:03

    One way is to use the method :

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

    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.

    Edit: Yes the asp.net mvc OutputCache is just a wrapper .

    If you're using varyByParam="none" then you just invalidate "/Statistics" - that's if / are querystring values. This will invalidate all versions of the page.

    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.

提交回复
热议问题