• <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

            文章均收錄自他人博客,但不喜標(biāo)題前加-[轉(zhuǎn)貼],因其丑陋,見(jiàn)諒!~
            隨筆 - 1469, 文章 - 0, 評(píng)論 - 661, 引用 - 0
            數(shù)據(jù)加載中……

            HTTP/1.1 Cache-Control的理解

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

            項(xiàng)目中使用過(guò)濾器來(lái)設(shè)置網(wǎng)頁(yè)的緩存

            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> 


            上述設(shè)置保存了1周的緩存。

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

            亚洲午夜无码AV毛片久久| 久久久久久综合网天天| 国产成人精品白浆久久69| 国产精品无码久久综合| 久久r热这里有精品视频| 亚洲欧美日韩精品久久亚洲区| 亚洲精品乱码久久久久久蜜桃不卡| 亚洲精品无码专区久久久| 丁香久久婷婷国产午夜视频| yellow中文字幕久久网| 狠狠色丁香久久婷婷综合蜜芽五月| 色综合久久中文字幕无码| 久久av高潮av无码av喷吹| 蜜臀久久99精品久久久久久小说| 精品国产青草久久久久福利| 久久精品国产亚洲AV香蕉| 久久天天躁狠狠躁夜夜96流白浆| 看全色黄大色大片免费久久久| 久久精品国产亚洲综合色| 久久综合狠狠综合久久| 精品伊人久久久| 四虎国产精品成人免费久久| 精品久久久无码人妻中文字幕豆芽| 久久婷婷人人澡人人| 国产精品欧美久久久久无广告 | 亚洲精品无码专区久久同性男| 久久99精品国产自在现线小黄鸭| 久久精品国产只有精品66| 久久影院亚洲一区| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 人妻无码久久一区二区三区免费| 婷婷久久精品国产| 久久国产影院| 青春久久| 久久久久亚洲AV片无码下载蜜桃| 精品久久久久久久国产潘金莲| 久久婷婷五月综合成人D啪 | 亚洲AV无码久久精品成人 | 99久久免费国产精精品| 精品一区二区久久久久久久网站| 久久精品国产亚洲综合色|