• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            woaidongmao

            文章均收錄自他人博客,但不喜標題前加-[轉貼],因其丑陋,見諒!~
            隨筆 - 1469, 文章 - 0, 評論 - 661, 引用 - 0
            數據加載中……

            HTTP/1.1 Cache-Control的理解

                 網頁的緩存是由HTTP消息頭中的“Cache-control”來控制的,常見的取值有privateno-cachemax-agemust-revalidate等,默認為private。其作用根據不同的重新瀏覽方式分為以下幾種情況:
            1) 打開新窗口
            如果指定cache-control的值為privateno-cachemust-revalidate,那么打開新窗口訪問時都會重新訪問服務器。而如果指定了max-age值,那么在此值內的時間里就不會重新訪問服務器,例如:
            Cache-control: max-age=5
            表示當訪問此網頁后的5秒內再次訪問不會去服務器
            2) 在地址欄回車
            如果值為privatemust-revalidate(和網上說的不一樣),則只有第一次訪問時會訪問服務器,以后就不再訪問。如果值為no-cache,那么每次都會訪問。如果值為max-age,則在過期之前不會重復訪問。
            3) 按后退按扭
            如果值為privatemust-revalidatemax-age,則不會重訪問,而如果為no-cache,則每次都重復訪問
            4) 按刷新按扭
            無論為何值,都會重復訪問
            clip_image001

            項目中使用過濾器來設置網頁的緩存

            clip_image002FilterConfig fc;
            clip_image002
            clip_image002   
            public void doFilter(ServletRequest req, ServletResponse res,
            clip_image003clip_image004            FilterChain chain)
            throws IOException, ServletException clip_image005{
            clip_image006        HttpServletResponse response = (HttpServletResponse) res;
            clip_image006       
            // set the provided HTTP response parameters
            clip_image007clip_image008
                    for (Enumeration e = fc.getInitParameterNames(); e.hasMoreElements();) clip_image005{
            clip_image006            String headerName = (String) e.nextElement();
            clip_image006            response.addHeader(headerName, fc.getInitParameter(headerName));
            clip_image009        }
            clip_image006       
            // pass the request/response on
            clip_image006
                    chain.doFilter(req, response);
            clip_image010    }


            配置文件的配置:

            clip_image002<filter>
            clip_image002       
            <filter-name>NoCache</filter-name>
            clip_image002       
            <filter-class>filter.CacheFilter</filter-class>
            clip_image002       
            <init-param>
            clip_image002           
            <param-name>Cache-Control</param-name>
            clip_image002           
            <param-value>no-cache, must-revalidate</param-value>
            clip_image002       
            </init-param>
            clip_image002   
            </filter>
            clip_image002   
            <filter>
            clip_image002       
            <filter-name>CacheForWeek</filter-name>
            clip_image002       
            <filter-class>filter.CacheFilter</filter-class>
            clip_image002       
            <init-param>
            clip_image002           
            <param-name>Cache-Control</param-name>
            clip_image002           
            <param-value>max-age=604800</param-value>
            clip_image002       
            </init-param>
            clip_image002   
            </filter>
            clip_image002
            clip_image002   
            <filter-mapping>
            clip_image002       
            <filter-name>CacheForWeek</filter-name>
            clip_image002       
            <url-pattern>*.js</url-pattern>
            clip_image002   
            </filter-mapping>
            clip_image002   
            <filter-mapping>
            clip_image002       
            <filter-name>CacheForWeek</filter-name>
            clip_image002       
            <url-pattern>*.css</url-pattern>
            clip_image002   
            </filter-mapping> 
            clip_image002   
            <filter-mapping>
            clip_image002       
            <filter-name>CacheForWeek</filter-name>
            clip_image002       
            <url-pattern>*.gif</url-pattern>
            clip_image002   
            </filter-mapping> 


            上述設置保存了1周的緩存。

            posted on 2009-09-10 11:48 肥仔 閱讀(1556) 評論(0)  編輯 收藏 引用 所屬分類: HTTP & URL

            久久久久久久综合综合狠狠| 色婷婷综合久久久久中文字幕| 久久精品夜夜夜夜夜久久| 丰满少妇人妻久久久久久| 久久一区二区免费播放| 蜜臀av性久久久久蜜臀aⅴ | 久久露脸国产精品| 亚洲精品乱码久久久久66| 狠狠综合久久综合中文88| 亚洲伊人久久大香线蕉综合图片| 日本道色综合久久影院| 日产精品久久久一区二区| 亚洲国产婷婷香蕉久久久久久| 亚洲国产精品久久久久网站 | 国产亚洲精久久久久久无码 | 国产精品成人99久久久久| 色婷婷综合久久久久中文 | 精品久久国产一区二区三区香蕉| 久久亚洲精品成人AV| 麻豆av久久av盛宴av| 亚洲精品tv久久久久久久久久| segui久久国产精品| 嫩草影院久久国产精品| 少妇精品久久久一区二区三区| 一本久道久久综合狠狠躁AV| 久久精品国产国产精品四凭| 久久亚洲高清观看| 久久青青草原综合伊人| 大伊人青草狠狠久久| 国产精品福利一区二区久久| 久久精品毛片免费观看| 久久久婷婷五月亚洲97号色| 色欲久久久天天天综合网| 久久久久久国产精品美女 | 久久久久亚洲AV无码专区网站| 91亚洲国产成人久久精品| 91精品国产91久久| 成人亚洲欧美久久久久| 午夜精品久久久久久久无码| 日韩十八禁一区二区久久| 国产精品乱码久久久久久软件 |