Squid proxy not caching anything

6,047

Oh, crap, I figured it out.

Squid ignores cache headers less than OR EQUAL TO one minute. So max-age=60 is ignored, but max-age=61 works like a charm.

<?php
Header('Cache-Control: max-age=61');

?><html>hi</html>
Share:
6,047

Related videos on Youtube

Dan Fabulich
Author by

Dan Fabulich

Updated on September 18, 2022

Comments

  • Dan Fabulich
    Dan Fabulich over 1 year

    squid.conf:

    http_access allow all
    
    # Squid normally listens to port 3128
    http_port 3128 accel defaultsite=localhost no-vhost
    
    cache_peer localhost parent 80 0 no-query originserver name=myAccel
    cache_peer_access myAccel allow all
    
    # Uncomment and adjust the following to add a disk cache directory.
    cache_dir ufs /usr/local/var/cache/squid 100 16 256
    
    # Leave coredumps in the first cache dir
    coredump_dir /usr/local/var/cache/squid
    

    Squid 3.2.9, installed on OSX via Homebrew

    localhost: ~ $ squid -v
    Squid Cache: Version 3.2.9
    configure options:  '--disable-debug' '--disable-dependency-tracking' '--prefix=/usr/local/Cellar/squid/3.2.9' '--localstatedir=/usr/local/var' 'CC=cc' 'CXX=c++' 'PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig'
    

    Started squid with squid -f squid.conf -d 2 -N

    The upstream is returning valid Cache-Control headers, which I've verified are correct by visiting the page in Google Chrome 26 and watching in Chrome Dev Tools.

    localhost: ~ $ curl -s -o /dev/null --dump-header /dev/stdout  http://localhost/test.php
    HTTP/1.1 200 OK
    Date: Tue, 16 Apr 2013 21:29:33 GMT
    Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch mod_ssl/2.2.22 OpenSSL/0.9.8r
    X-Powered-By: PHP/5.3.15
    Cache-Control: max-age=60, public
    Content-Length: 16
    Content-Type: text/html
    X-Pad: avoid browser bug
    

    But when I query the page via the Squid reverse proxy, I always get a cache miss.

    localhost: ~ $ curl -s -o /dev/null --dump-header /dev/stdout  http://localhost:3128/test.php
    HTTP/1.1 200 OK
    Date: Tue, 16 Apr 2013 21:29:34 GMT
    Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch mod_ssl/2.2.22 OpenSSL/0.9.8r
    X-Powered-By: PHP/5.3.15
    Cache-Control: max-age=60, public
    Content-Length: 16
    Content-Type: text/html
    X-Cache: MISS from localhost
    Via: 1.1 localhost (squid/3.2.9)
    Connection: keep-alive
    
    localhost: ~ $ curl -s -o /dev/null --dump-header /dev/stdout  http://localhost:3128/test.php
    HTTP/1.1 200 OK
    Date: Tue, 16 Apr 2013 21:29:38 GMT
    Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch mod_ssl/2.2.22 OpenSSL/0.9.8r
    X-Powered-By: PHP/5.3.15
    Cache-Control: max-age=60, public
    Content-Length: 16
    Content-Type: text/html
    X-Cache: MISS from localhost
    Via: 1.1 localhost (squid/3.2.9)
    Connection: keep-alive
    

    What's wrong with my configuration?

    • James O'Gorman
      James O'Gorman about 11 years
      The cache-control header sets max-age to 60, which is the same as squid's default minimum_expiry_time - try tweaking this value in squid.
  • James O'Gorman
    James O'Gorman about 11 years
    Or you can tweak maximum_expiry_time in squid - which is recommended for this type of environment. :-)
  • Dan Fabulich
    Dan Fabulich about 11 years
    minimum_expiry_time, yes. (You got it right in the comment to the question.)