웹개발 하다보면 캐쉬된 페이지때문에 가끔 웹브라우저가 재시동하거나, 웹서버를 재시동하는 경우가 있었을 것이다. 그런 경우 캐쉬에서 불러오는 것이 아니라 항상 최신의 페이지를 보여주도록 하는 방법입니다. 데이터가 넘어가는 경우에만 '만료된 페이지입니다' 라는 메시지를 보여주게 됩니다.
ERR_CACHE_MISS 이런 에러를 마주할 수 있을 것 이다. 나 같은 경우는 뒤로 가기 버튼을 눌렀는데 캐쉬를 불러오지 못해서 크롬에서 에러가 난다. 그럴 경우에 No-cache를 jsp에 설정해두었더니 에러가 해결되었다.

다음은 각각의 케이스별 No-Cache 설정방법입니다.
HTML인 경우
<META http-equiv="Expires" content="-1">
<META http-equiv="Pragma" content="no-cache">
<META http-equiv="Cache-Control" content="No-Cache">
ASP인 경우
<%
Response.Expires = 0
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "Cache-Control","no-cache,must-revalidate"
%>
JSP인 경우
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader("Expires",0);
if (request.getProtocol().equals("HTTP/1.1"))
response.setHeader("Cache-Control", "no-cache");
%>
PHP인 경우
<?
header("Pragma: no-cache");
header("Cache-Control: no-cache,must-revalidate");
?>
[ 참고 사이트 ]
728x90
댓글