mod_cache forgets to include cached headers when serving cached content under certain circumstances (2.2.x)

2016-05-23 Thread Rob Landrito
Under a very specific set of circumstances, apache proxy will not serve
the correct headers for cached content.  This was observed under 2.2.29
and seems to exist in the 2.2.31 release.

The problem occurs when a client revalidates content that is both
already cached on the client, and on the proxy.  Revalidation is
requested by the client via the If-Modified-Since header.  If the
upstream webserver responds to the revalidation with a 304 Not Modified
that also contains headers indicating non-cacheable content, the proxy
will serve its cached content to the client, but without the appropriate
headers.  This can result in errors on the client side as content
encoding and content type information is lost.

The specific circumstance is described in a comment in mod_cache:

/* Hold the phone. Some servers might allow us to cache a 2xx, but
 * then make their 304 responses non cacheable. This leaves us in a
 * sticky position. If the 304 is in answer to our own conditional
 * request, we cannot send this 304 back to the client because the
 * client isn't expecting it. Instead, our only option is to respect
 * the answer to the question we asked (has it changed, answer was
 * no) and return the cached item to the client, and then respect
 * the uncacheable nature of this 304 by allowing the remove_url
 * filter to kick in and remove the cached entity.
 */

The code proceeds to push the cached content onto the bucket brigade but
neglects to apply the matching cached headers.

Originally I thought the solution would be to simply add the cached
headers but in the 2.4.x branch, it seems that this case is handled by
re-requesting the resource without the conditional.  Should this code be
backported into the the 2.2.x branch ?


Re: htcacheclean and expired cache entries

2011-12-05 Thread Rob Landrito
Thanks for the response.  You're right, the -L option would be ideal.  We
probably won't be going to 2.4 for some time after release so I'll see if I
can't backport htcacheclean to 2.2.

Cheers

2011/12/2 Graham Leggett minf...@sharp.fm

 On 02 Dec 2011, at 8:52 PM, Rob Landrito wrote:

  I noticed that htcacheclean won't clean expired entries unless the
 specified size limit is reached.

 That's by design.

   Is there any specific reason for this ?  I'm looking into freeing up
 some inodes on some of my servers where the total cache size hasn't reached
 my specified limit.  Would it be worthwhile to add a switch to enable
 cleaning of expired entries even if the size limit isn't reached ?


 The short answer is that you're probably looking for the -L option in the
 (soon to be released) httpd v2.4 to limit to the given number of inodes, as
 described here:

 http://httpd.apache.org/docs/trunk/programs/htcacheclean.html#options

 You probably want to use both the -l and -L options together to keep files
 safely within limits on disk.

 To answer your question, creating content has a cost associated with it,
 you want to keep content around for as long as humanly possible. Unlike
 typical caching systems that have a dual state it's cached / it's
 deleted, HTTP caching offers a three state system: it's fresh / it's
 stale / it's deleted.

 Initially, when cached, content is typically fresh for a freshness
 lifetime, and when it gets old enough, the content goes into the second
 state, that of being stale. Using the conditional request mechanism,
 the backend server is given the opportunity to confirm whether the stale
 content is actually still fresh, and in many cases this is so. The stale
 content is then updated to be fresh again. Eventually, the cache becomes
 full, so htcacheclean kicks in and reduces the cache size until it fits
 inside the given limits, but no more.

 Apart from the obvious benefit of not having to regenerate content from
 scratch when it goes stale, having stale content available allows you to do
 some useful things, like serve stale content to a thundering herd while the
 stale content is being freshened, or returning stale content when the
 backend returned an error. None of this is possible if you strip the cache
 of stale data.

 Regards,
 Graham
 --




-- 
:wq!


htcacheclean and expired cache entries

2011-12-02 Thread Rob Landrito
Greetings,

I noticed that htcacheclean won't clean expired entries unless the
specified size limit is reached.  Is there any specific reason for this ?
 I'm looking into freeing up some inodes on some of my servers where the
total cache size hasn't reached my specified limit.  Would it be worthwhile
to add a switch to enable cleaning of expired entries even if the size
limit isn't reached ?