Looking at the response headers, it's possible that the URL isn't
being cached at all by squid because there's no Last-Modified or Cache-
Control: max-age header. IIRC (Amos, correct me if I'm wrong here),
Squid will assume that content without a Last-Modified header is
dynamic content and not cache it, unless there's a max-age header
giving it an explicit cache age.
And if squid isn't caching the URL, then there's nothing to serve up
if the backend server is unavailable.
You can test this by looking for "X-Cache: HIT" (or MISS) the second
time you request the URL before you shut the back-end server down.
If the URL isn't being cached, the easiest fix IMO would be to add
"max-age=XXX" to your Cache-control: header, as in "Cache-Control: max-
age=300, stale-if-error=300". See if that solves the problem.
HTH,
-Chris
On Mar 27, 2009, at 8:53 AM, Dingwell, Robert A. wrote:
I¹m using 2.7STABLE6 which is why I¹m confused as to why it¹s not
working as
I thought it would. Are there any other headers that need to be
set as
well in order for the header to be used? I guess the other question
is am I
wrong in my assumption to how this is suppose to work? My assumption
is that
if squid receives a stale-if-error cache directive it will cache that
response and then if there is an error contacting the origin server
the the
cached response will be served up instead. Is that correct?
Below are the headers that are being emitted from the server I am
testing
against.
HTTP/1.1 200 OK
Date: Thu, 26 Mar 2009 13:59:36 GMT
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en-US
Content-Length: 384
Cache-Control: stale-if-error=300
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
I currently expect squid to cache the content from this request.
Then I shut the origin down and the apache acting as a reverse proxy
ships
back a service unavailable response.
HTTP/1.1 503 Service Temporarily Unavailable
Date: Thu, 26 Mar 2009 14:00:26 GMT
Content-Length: 323
Connection: close
Content-Type: text/html; charset=iso-8859-1
This is were I would expect squid to give me back the first request.
Is this
a correct assumption?
Thanks for the help.
Rob
On 3/26/09 10:52 PM, "Amos Jeffries" <squid3@xxxxxxxxxxxxx> wrote:
Dingwell, Robert A. wrote:
On 3/26/09 11:01 AM, "Dingwell, Robert A. (BOBD)" <bobd@xxxxxxxxx>
wrote:
I¹ve been trying to get a caching architecture setup so that if
a server I
am caching content for goes down or is more likely just
unavailable to do
network issues I can have the cache serve up the stale content.
In the
production environment that this will be used I will not have the
ability to
have all of the services involved set cache control headers on
their data.
We
are operating on a wan with people all over the globe so it
would be really
difficult to get everyone to do that. What I can do though is to
make sure
that everything goes through apache acting as a reverse proxy
which then
sets
the Cache-Control header, which I have done and verified that it
does indeed
do what I want it to.
So now I fire up squid and apache and attempt to access a server
I have
control over and I get back the data I expect to get back. Look
in the
squid
log file see the header in the log ³Cache-Control: stale-if-
error=300² so I
know it¹s being sent. Now I shutdown the server I just accessed
and attempt
to access the same url. I expect to get back the same data that I
just got
back but instead I get back the error page saying the service is
unavailable.
Shouldn¹t squid be serving up the stale content? Or am I missing
a step.
The
other odd thing is once I start the server back up it takes a
couple of
minutes to get back the page from server as squid seams to be
caching the
error page.
I know that stale-if-error is only going to work for 500-504
errors but
looking through the squid logs again I see that I am getting an
error code
back when I try to access the page when it¹s down ³HTTP/1.1 503
Service
Temporarily Unavailable².
One last thing this article , http://www.mnot.net/blog/2007/12/12/stale
,
makes it sound like squid has a configuration parameter that is
used to
enable
stale-if-error even when the server does not send the control
header. Does
anyone know if this exists or what the magic incantation is to
get it
working?
Anybody have any ideas as to what I may be doing wrong, or an
alternative
approach to accomplishing what I am trying to get working? I
already tried
using offline mode which did not work and I think isn¹t really
what I would
want to do anyway as I need squid to attempt to access the server
and serve
up
the stale data only when the server is down.
Any help is appreciated ,
Thanks
Rob
Depends.
Squid-2.7 supports it, the others do not yet though there is a
patch for
Squid-3.1 in bugzilla awaiting someone to test it properly.
Amos
--
Please be using
Current Stable Squid 2.7.STABLE6 or 3.0.STABLE13
Current Beta Squid 3.1.0.6