No-Cache 설정

기타 | 2007. 5. 9. 10:48
Posted by 시반

JSP에서 No-Cache 설정하는 방법

웹개발 하다보면 캐쉬된 페이지때문에 가끔 웹브라우저가 재시동하거나, 웹서버를 재시동하는 경우가 있었을 것이다. 그런 경우 캐쉬에서 불러오는 것이 아니라 항상 최신의 페이지를 보여주도록 하는 방법입니다. 데이터가 넘어가는 경우에만 '만료된 페이지입니다' 라는 메시지를 보여주게 되져

다음은 각각의 케이스별 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");  
?>



헌데 Struts Framework 사용시에는 아래와 같은 설정을 꼭 해주셔야 위의 내용이 적용이 된다고 하네요.(스트럿츠를 안써서리 잘 모르겠지만...)

 


processNoCache()는 struts-config.xml설정파일의 <controller>설정에서 nocache attribute가 true로 설정되어 있을 경우 호출된다.

만약 true라면 response객체의 header에 Pragma, Cache-Control, Expires가 추가되게 된다. 스트러츠 Framework에서는 struts-config.xml설정파일에 단지 true로 설정해주면 Cache가 적용되지 않는다.

즉 <controller nocache="true" />라는 설정을 struts-config.xml에 추가하면 끝.


 

 
블로그 이미지

시반

시반(詩伴)이란 함께 시를 짓는 벗이란 뜻을 가지고 있습니다. 함께 나눌수 있는 그런 공간이길 바라며...

카테고리

분류 전체보기 (233)
개발 이야기 (73)
WEB2.0 (57)
DB2 (24)
MySQL (6)
오라클 (26)
기타 (44)
취미 (0)
잡담 (2)