Re: [squid-users] Squid Reverse Proxy (accel) always contacting the server

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Sat, 31 Mar 2012 21:13:57 +1300

On 30/03/2012 12:47 p.m., Daniele Segato wrote:
> Hi,
>
> This is what I want to obtain:
>
> Environment:
> * everything on the same machine (Debian GNU\Linux)
> * server running on tomcat, port 8080
> * squid running on port 280
> * client can be anywhere, but for now it's on the localhost machine too
>
> I want to set up an http cache to my tomcat server to reduce the load
> on it.
>
> And I expect to obtain a result like this:
>
> First request
> 1. 9:00 AM (today) client request GET to http://localhost:280/myservice
> 2. squid receive the request, nothing in cache, contact my server
> 3. tomcat reply with a 200, the body and some header:
> Cache-Control: public, max-age=3600
> Last-Modified: //8:00 AM//
> 4. squid store in cache that result that should be valid until 10:00
> AM (today) = 9:00 AM (time of the request) + 3600 seconds (max-age)
> 5. client receive the response
>
> Second request:
> 1. 9:05 AM (today) client request GET to
> http://localhost:280/myservice with header
> If-Modified-Since: //8:00 AM//
> 2. squid receive the request, see 9:05 AM < 10:00 AM --> cache hit 304
> 3. client receive the response 304
>
> Third request (after 10:00 AM)
> 1. 10:05 AM (today) client request GET to
> http://localhost:280/myservicewith header
> If-Modified-Since: //8:00 AM//
> 2. squid receive the request, see 10:05 AM > 10:00 AM --> time to see
> if the server has a new version, forward the if-modified-since request
> to the server
> 3. suppose the resource is not changed: tomcat reply with a 304 Not
> Modified, again with headers:
> Cache-Control: public, max-age=3600
> Last-Modified: //8:00 AM//
> 4. squid store update the cache value to be valid until 11:05 AM
> (today) = 10:05 AM (time of the request) + 3600 seconds (max-age)
> 5. client receive the response: 304 Not Modified
>
>
>
> Instead squid is ALWAYS requiring the resource to the server:
> $ curl -v -H 'If-Modified-Since: Thu, 29 Mar 2012 22:14:20 GMT'
> 'http://localhost:280/alfresco/service/catalog/products'
>
> * About to connect() to localhost port 280 (#0)
> * Trying 127.0.0.1...
> * connected
> * Connected to localhost (127.0.0.1) port 280 (#0)
>> GET /alfresco/service/catalog/products HTTP/1.1
>> User-Agent: curl/7.24.0 (x86_64-pc-linux-gnu) libcurl/7.24.0
> OpenSSL/1.0.0h zlib/1.2.6 libidn/1.24 libssh2/1.2.8 librtmp/2.3
>> Host: localhost:280
>> Accept: */*
>> If-Modified-Since: Thu, 29 Mar 2012 22:14:20 GMT
>>
> * additional stuff not fine transfer.c:1037: 0 0
> * HTTP 1.0, assume close after body
> < HTTP/1.0 304 Not Modified
> < Date: Thu, 29 Mar 2012 23:27:57 GMT
> < Cache-Control: public, max-age=3600
> < Last-Modified: Thu, 29 Mar 2012 22:14:20 GMT

"

    max-age

       The max-age response directive indicates that the response is to
       be considered stale after its age is greater than the specified
       number of seconds.

"

The logic goes like this:

   Object modified ... 22:14:20
   Valid +3600
    ==> fresh until 23:14:50
   Current time: 23:27:57

    23:14:50 < 23:27:15 ==> currently stale. must revalidate.

Expires header can be used to set an absolute time for invaldation.
max-age is relative to age.

Amos
Received on Sat Mar 31 2012 - 08:14:06 MDT

This archive was generated by hypermail 2.2.0 : Sat Mar 31 2012 - 12:00:04 MDT