• <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 肥仔 閱讀(1550) 評論(0)  編輯 收藏 引用 所屬分類: HTTP & URL

            精品免费久久久久久久| 99久久精品免费看国产| 精品久久久久久综合日本| 日批日出水久久亚洲精品tv| 久久久久女人精品毛片| 久久夜色精品国产噜噜亚洲a| 久久99国产精品成人欧美| 97久久久精品综合88久久| 欧美亚洲色综久久精品国产| 狠狠色丁香久久婷婷综合_中| 久久精品免费大片国产大片| 国产高清国内精品福利99久久| 99久久99久久精品免费看蜜桃| 久久久久无码精品国产不卡| 日韩人妻无码精品久久久不卡 | 亚洲精品无码久久久久| 亚洲精品综合久久| 久久久久人妻一区精品| 久久亚洲欧洲国产综合| 中文字幕久久亚洲一区| 亚洲AV无码久久| 九九久久99综合一区二区| 国产成人综合久久久久久| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 日本精品久久久久影院日本| 久久青青国产| 久久亚洲AV无码精品色午夜麻豆 | 精品国产VA久久久久久久冰| 国产一区二区三区久久| 91亚洲国产成人久久精品| 少妇久久久久久被弄到高潮 | 国产A级毛片久久久精品毛片| 亚洲精品乱码久久久久久| 久久久久亚洲av无码专区喷水| 久久国产精品久久| 久久综合偷偷噜噜噜色| 狠狠狠色丁香婷婷综合久久俺| 久久久久国产成人精品亚洲午夜| 精品熟女少妇AV免费久久| 日本福利片国产午夜久久|