You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dziugas Baltrunas <dz...@gmail.com> on 2007/02/12 09:49:06 UTC

mod_cache: MISS or HIT

Hi list,

I'm using httpd 2.2.4 as both reverse and forward proxy having caching
enabled with mod_cache.

I'm trying to figure out the way how to put information in access log
(via mod_log_config) whether the request was a cache hit or miss
(similar to what squid does -  TCP_MISS and TCP_HIT). I think this
information is necessary for any proxy server (or acting like it) and
it's always wise to know hit/miss ratio.

Since at least officially mod_cache (and it's sub-modules) does not
export such information, I thought about registering custom
mod_log_config tag (via log_pfn_register). However, looking at the
mod_*_cache source and trying to distinguish cache request from an
ordinary one didn't seem trivial. Just several observations so far:

1. In case it's HIT, output goes over CACHE_OUT, otherwise it's
CACHE_SAVE. Q: is it possible for external module to check (e.g. by
traversing r->output_filters) which filter _was_ used?

2. For mod_file_cache there is a possible "workaround" to rely on
r->clength which is set to match->finfo.size (inside mod_file_cache.c)
in case we have CACHE_OUT. clength seems to be referenced nowhere else
except mod_file_cache.c and http/http_protocol.c where it's set to 0.
However, for mod_mem_cache things are different.

Thanks.

-- 
Dziugas Baltrunas

Re: mod_cache: MISS or HIT

Posted by Dziugas Baltrunas <dz...@gmail.com>.
Hi,

I was looking for something more reliable so I now realize it will
require patching of mod_cache.c by adding some flag (i.e. setting some
key r->notes, registering mod_log_config modifier via log_pfn_register
or similar).

On 2/12/07, Joshua Slive <jo...@slive.ca> wrote:
> On 2/12/07, Dziugas Baltrunas <dz...@gmail.com> wrote:
>
> > I'm trying to figure out the way how to put information in access log
> > (via mod_log_config) whether the request was a cache hit or miss
> > (similar to what squid does -  TCP_MISS and TCP_HIT). I think this
> > information is necessary for any proxy server (or acting like it) and
> > it's always wise to know hit/miss ratio.
>
> You can log the Age HTTP response header for this.  If it is present,
> you have a cache hit, and if not, a miss.
>
> Of course, this probably wouldn't be reliable if your cache was in
> front of another cache.  But it works in most circumstances.
>
> Joshua.
>


-- 
Dziugas

Re: mod_cache: MISS or HIT

Posted by Joshua Slive <jo...@slive.ca>.
On 2/12/07, Dziugas Baltrunas <dz...@gmail.com> wrote:

> I'm trying to figure out the way how to put information in access log
> (via mod_log_config) whether the request was a cache hit or miss
> (similar to what squid does -  TCP_MISS and TCP_HIT). I think this
> information is necessary for any proxy server (or acting like it) and
> it's always wise to know hit/miss ratio.

You can log the Age HTTP response header for this.  If it is present,
you have a cache hit, and if not, a miss.

Of course, this probably wouldn't be reliable if your cache was in
front of another cache.  But it works in most circumstances.

Joshua.