Hello

I'm trying to set caching for 1 year for my static context (js,css and
images)
however seems like caching is only done for 2-3 weeks. below I put my
caching filter
and a response for some js file request.

I've added this code in a special "catch-all" filter and verified that all
resources
are indeed going through this filter :

    // cache for 1 year
    private static final long _cacheTime = (1000 * 60 * 60 * 24 * 365);

    public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {

        HttpServletRequest hreq = (HttpServletRequest)req;
        HttpServletResponse hres = (HttpServletResponse)res;

        hreq.setCharacterEncoding("UTF-8");

        hres.setHeader("Vary", "Accept-Encoding");
                hres.setCharacterEncoding("UTF-8");
        // put caching for 1 year for images and js, css files

        if ((path.endsWith(".png")) || (path.endsWith(".jpg")) ||
(path.endsWith(".gid"))) {
            // put caching for 1 year for images and js, css files
            hres.setHeader("Cache-Control", "public: max-age=31536000");
            hres.setDateHeader("Expires", Utils.now().getTime() +
_cacheTime);
        } else if ((path.endsWith(".js")) || (path.endsWith(".css"))) {
            // put caching for 1 year for images and js, css files
            hres.setHeader("Cache-Control", "public: max-age=31536000");
            hres.setDateHeader("Expires", Utils.now().getTime() +
_cacheTime);
        } else {
            // don't cache servlets or HTML - override headers
            hres.setHeader("Pragma", "no-cache");
            hres.setHeader("Cache-Control", "private, no-store, no-cache,
must-revalidate");
            hres.setHeader("Expires", "0");
        }
        passFilter(req, res, chain);
    }


now the problem is that the caching is set "only" for something like 2-3
weeks.
here is an example of response headers for some js file :
*
*

   1. Request URL:
   http://www.ichess.co.il/scripts/tiny_mce/tiny_mce.js
   2. Request Method:
   GET
   3. Status Code:
   200 OK
   4. Request Headers
      1. Accept:
      */*
      2. Referer:
      http://www.ichess.co.il/
      3. User-Agent:
      Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10
      (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10
      5. Response Headers
      1. Accept-Ranges:
      bytes
      2. Age:
      138
      3. Cache-Control:
      public: max-age=31536000
      4. Connection:
      Keep-Alive
      5. Content-Length:
      181324
      6. Content-Type:
      text/javascript;charset=UTF-8
      7. *Date:*
      *Sun, 16 Jan 2011 07:40:28 GMT*
      8. ETag:
      W/"181324-1294691843184"
      9. *Expires:*
      *Wed, 02 Feb 2011 08:20:57 GMT*
      10. Last-Modified:
      Mon, 10 Jan 2011 20:37:23 GMT
      11. Proxy-Connection:
      Keep-Alive
      12. Server:
      Apache-Coyote/1.1
      13. Vary:
      Accept-Encoding
      14. Via:
      1.1 TLVPROXY01




-- 
רן ברנפלד
מנהל
אתר השחמט הישראלי
*http://www.ichess.co.il*

Reply via email to