HttpServletResponse res;
//Cache-Control HTTP1.1
//Pragma Expires HTTP1.0

res.setHeader( "Pragma", "no-cache" );  //與Cache-Control: no-cache相同,會被Cache-Control覆蓋
res.addHeader( "Cache-Control", "must-revalidate" ); 
res.addHeader( "Cache-Control", "no-cache" );  //發request向server確認是否取得新資料
res.addHeader( "Cache-Control", "no-store" );   //完全不Cache
res.setDateHeader("Expires", 0);  //CACHE過期時間,與Cache-Control: max-age相同,會被Cache-Control覆蓋

 

被Cache資料,可以從DevTool看到 from disk cache的字樣,以及max-age存活時間
如果程式調整了資料沒有改變,建議先來確定瀏覽器的狀況

aaa.JPG

 

 

參考資料:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Caching_FAQ#Cache_validation

arrow
arrow
    文章標籤
    JAVA Cache Cache-Control
    全站熱搜

    咪卡恰比 發表在 痞客邦 留言(0) 人氣()