Force Cache Refresh When Editing and Redisplaying Content

此生再无相见时 提交于 2019-12-30 10:45:13

问题


I am using asp.net mvc and have a view that displays an item and a view that allows editing an item. When the user submits an edited item, it redirects them to the view for that item. The changes are not being reflected when they are redirected because the item view is being cached. The view item page can also be edited inline and then a submit button uses javascript to submit and then refresh the page.

I've noticed that stackoverflow somehow makes this work when you edit an item, it redirects you to the page with your changes reflected. Their caching is set to public, max-age=120 so I am surprised the browser doesn't pull a local copy without the reflected changes...

Anyway, is there a way to force a cache refresh in these cases? I would prefer not to append a random query string value, but if there is no other way that is what I will do.


回答1:


There is a cache-control meta tag you can set. Put this in your head section

<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

http://www.chami.com/tips/internet/113096I.html

or the .Net way

<%@ OutputCache Location="None" VaryByParam="None" %>

http://www.dailycoding.com/Posts/how_not_to_cache_a_page_output_in_aspnet.aspx



来源:https://stackoverflow.com/questions/5629299/force-cache-refresh-when-editing-and-redisplaying-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!