You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modproxy-dev@apache.org by rb...@covalent.net on 2000/11/15 15:34:12 UTC

mod_cache.c

I am posting a copy of mod_cache.c, which is a VERY simple cache module
for Apache 2.0.  This basically implements a file cache filter and with
some work it can be abstracted to other cache types.  The reason I am not
committing it, is because this is horribly broken right now.  It never
reads from the cache to try to serve that page, and it always caches to
the same file.  :-)  The first problem is just a matter of writing a
handler.  The second is even easier, we need to rip the logic out of the
current file_cache directory to get a valid key for the file.

I have added comments for where things should be abstracted so that
different back-ends can be used.  I don't want this to fall on the floor,
and if this stays on my hard-drive, it will not see the light of day for
at least a month.  So, have at it and if anybody wants to pick this up,
let me know.  I want to help, but I am stretched too thin to do the cache
myself.  :-)


#include "apr_strings.h"
#include "ap_config.h"
#include "util_filter.h"
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
#include "http_core.h"                                                             

module MODULE_VAR_EXPORT cache_module;

typedef struct cache_struct {
    char *filename;
    apr_file_t *fd;
    int state;
} cache_struct;

static int cache_filter(ap_filter_t *f, ap_bucket_brigade *bb)
{
    cache_struct *ctx;
    ap_bucket *e;
    
    if (ctx == NULL) {
        f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
    }
    ctx->state = 1;
    if (ctx->state) {
        return ap_pass_brigade(f->next, bb);
    }
    if (ctx->filename == NULL) {
        apr_status_t rv;
        ctx->filename = ap_server_root_relative(f->r->pool, "logs/cachefile");
/* XXX Cache modules should abstract out the open call */
        if ((rv = apr_open(&ctx->fd, ctx->filename, 
                     APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED,
                     APR_UREAD | APR_UWRITE, f->r->pool)) != APR_SUCCESS) {
            ap_log_error(APLOG_MARK, APlOG_ERROR, rv, f->r,
                         "Could not create cache file");
            return ap_pass_brigade(f->next, bb);
        }
    } 
    AP_BRIGADE_FOREACH(e, bb) {
        const char *str;
        apr_ssize_t length;

        ap_bucket_read(e, &str, &length, 0);
/* XXX Cache modules should abstract out the write call */
        apr_write(ctx->fd, str, length);
    }
    ap_pass_brigade(f->next, bb);
    return APR_SUCCESS;	
}

static void cache_register_hook(void)
{
    ap_register_output_filter("CACHE", cache_filter, AP_FTYPE_HTTP_HEADER);
}

module MODULE_VAR_EXPORT cache_module = {
    STANDARD20_MODULE_STUFF,
    NULL,			/* create per-directory config structure */
    NULL,        		/* merge per-directory config structures */
    NULL,			/* create per-server config structure */
    NULL,			/* merge per-server config structures */
    NULL,			/* command apr_table_t */
    NULL,          		/* handlers */
    cache_register_hook		/* register hooks */
};


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------



Re: mod_cache.c

Posted by Chuck Murcko <ch...@topsail.org>.
Greg Stein wrote:
> 
> ...snip...
> 
> While I agree with not wanting to lose the work, I think by posting it to
> new-httpd we're okay (and Bill's comment that Victor may want to work on
> it).
> 
> I'm -1 for putting it into the repository until we have a location that
> implies "in development; doesn't work".  modules/broken/ ?
> 
We've already got modules/proxy. 8^) Since it's going to get used there
first, it can go there for now. How's that?
-- 
Chuck
Chuck Murcko
Topsail Group
chuck@topsail.org

this is spam. Delete please.

Posted by Austin Gonyou <au...@coremetrics.com>.
Sorry for the spam. Test

Re: mod_cache.c

Posted by rb...@covalent.net.
> > This was never EVER intended to go into the repository yet.  I posted it
> > because people expressed interest in seeing how it works, and in using it
> > as a basis.  As things move forward, it will be committed when it is
> > ready.
> 
> Yup. Basically what I said.
> 
> Stop agreeing with me :-)

No!  I will not stop agreeing with you.  You stop saying what I mean.  :-)

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: mod_cache.c

Posted by rb...@covalent.net.
> > This was never EVER intended to go into the repository yet.  I posted it
> > because people expressed interest in seeing how it works, and in using it
> > as a basis.  As things move forward, it will be committed when it is
> > ready.
> 
> Yup. Basically what I said.
> 
> Stop agreeing with me :-)

No!  I will not stop agreeing with you.  You stop saying what I mean.  :-)

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: mod_cache.c

Posted by Greg Stein <gs...@lyra.org>.
On Wed, Nov 15, 2000 at 01:06:04PM -0800, rbb@covalent.net wrote:
> On Wed, 15 Nov 2000, Greg Stein wrote:
> > > I have added comments for where things should be abstracted so that
> > > different back-ends can be used.  I don't want this to fall on the floor,
> > > and if this stays on my hard-drive, it will not see the light of day for
> > > at least a month.  So, have at it and if anybody wants to pick this up,
> > > let me know.  I want to help, but I am stretched too thin to do the cache
> > > myself.  :-)
> > 
> > Normally, I'd say commit it to the experimental/ directory, but it hasn't
> > even reached an experimental point :-)  [ all the things in there at least
> > do what they say, even if they might not cover all boundary conditions ]
> > 
> > While I agree with not wanting to lose the work, I think by posting it to
> > new-httpd we're okay (and Bill's comment that Victor may want to work on
> > it).
> > 
> > I'm -1 for putting it into the repository until we have a location that
> > implies "in development; doesn't work".  modules/broken/ ?
> 
> This was never EVER intended to go into the repository yet.  I posted it
> because people expressed interest in seeing how it works, and in using it
> as a basis.  As things move forward, it will be committed when it is
> ready.

Yup. Basically what I said.

Stop agreeing with me :-)

-- 
Greg Stein, http://www.lyra.org/

Re: mod_cache.c

Posted by Greg Stein <gs...@lyra.org>.
On Wed, Nov 15, 2000 at 01:06:04PM -0800, rbb@covalent.net wrote:
> On Wed, 15 Nov 2000, Greg Stein wrote:
> > > I have added comments for where things should be abstracted so that
> > > different back-ends can be used.  I don't want this to fall on the floor,
> > > and if this stays on my hard-drive, it will not see the light of day for
> > > at least a month.  So, have at it and if anybody wants to pick this up,
> > > let me know.  I want to help, but I am stretched too thin to do the cache
> > > myself.  :-)
> > 
> > Normally, I'd say commit it to the experimental/ directory, but it hasn't
> > even reached an experimental point :-)  [ all the things in there at least
> > do what they say, even if they might not cover all boundary conditions ]
> > 
> > While I agree with not wanting to lose the work, I think by posting it to
> > new-httpd we're okay (and Bill's comment that Victor may want to work on
> > it).
> > 
> > I'm -1 for putting it into the repository until we have a location that
> > implies "in development; doesn't work".  modules/broken/ ?
> 
> This was never EVER intended to go into the repository yet.  I posted it
> because people expressed interest in seeing how it works, and in using it
> as a basis.  As things move forward, it will be committed when it is
> ready.

Yup. Basically what I said.

Stop agreeing with me :-)

-- 
Greg Stein, http://www.lyra.org/

Re: mod_cache.c

Posted by rb...@covalent.net.
On Wed, 15 Nov 2000, Greg Stein wrote:

> > I have added comments for where things should be abstracted so that
> > different back-ends can be used.  I don't want this to fall on the floor,
> > and if this stays on my hard-drive, it will not see the light of day for
> > at least a month.  So, have at it and if anybody wants to pick this up,
> > let me know.  I want to help, but I am stretched too thin to do the cache
> > myself.  :-)
> 
> Normally, I'd say commit it to the experimental/ directory, but it hasn't
> even reached an experimental point :-)  [ all the things in there at least
> do what they say, even if they might not cover all boundary conditions ]
> 
> While I agree with not wanting to lose the work, I think by posting it to
> new-httpd we're okay (and Bill's comment that Victor may want to work on
> it).
> 
> I'm -1 for putting it into the repository until we have a location that
> implies "in development; doesn't work".  modules/broken/ ?

This was never EVER intended to go into the repository yet.  I posted it
because people expressed interest in seeing how it works, and in using it
as a basis.  As things move forward, it will be committed when it is
ready.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: mod_cache.c

Posted by rb...@covalent.net.
On Wed, 15 Nov 2000, Greg Stein wrote:

> > I have added comments for where things should be abstracted so that
> > different back-ends can be used.  I don't want this to fall on the floor,
> > and if this stays on my hard-drive, it will not see the light of day for
> > at least a month.  So, have at it and if anybody wants to pick this up,
> > let me know.  I want to help, but I am stretched too thin to do the cache
> > myself.  :-)
> 
> Normally, I'd say commit it to the experimental/ directory, but it hasn't
> even reached an experimental point :-)  [ all the things in there at least
> do what they say, even if they might not cover all boundary conditions ]
> 
> While I agree with not wanting to lose the work, I think by posting it to
> new-httpd we're okay (and Bill's comment that Victor may want to work on
> it).
> 
> I'm -1 for putting it into the repository until we have a location that
> implies "in development; doesn't work".  modules/broken/ ?

This was never EVER intended to go into the repository yet.  I posted it
because people expressed interest in seeing how it works, and in using it
as a basis.  As things move forward, it will be committed when it is
ready.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: mod_cache.c

Posted by Greg Stein <gs...@lyra.org>.
On Wed, Nov 15, 2000 at 06:34:12AM -0800, rbb@covalent.net wrote:
> 
> I am posting a copy of mod_cache.c, which is a VERY simple cache module
> for Apache 2.0.  This basically implements a file cache filter and with
> some work it can be abstracted to other cache types.  The reason I am not
> committing it, is because this is horribly broken right now.  It never
> reads from the cache to try to serve that page, and it always caches to
> the same file.  :-)  The first problem is just a matter of writing a
> handler.  The second is even easier, we need to rip the logic out of the
> current file_cache directory to get a valid key for the file.
> 
> I have added comments for where things should be abstracted so that
> different back-ends can be used.  I don't want this to fall on the floor,
> and if this stays on my hard-drive, it will not see the light of day for
> at least a month.  So, have at it and if anybody wants to pick this up,
> let me know.  I want to help, but I am stretched too thin to do the cache
> myself.  :-)

Normally, I'd say commit it to the experimental/ directory, but it hasn't
even reached an experimental point :-)  [ all the things in there at least
do what they say, even if they might not cover all boundary conditions ]

While I agree with not wanting to lose the work, I think by posting it to
new-httpd we're okay (and Bill's comment that Victor may want to work on
it).

I'm -1 for putting it into the repository until we have a location that
implies "in development; doesn't work".  modules/broken/ ?

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: mod_cache.c

Posted by Greg Stein <gs...@lyra.org>.
On Wed, Nov 15, 2000 at 06:34:12AM -0800, rbb@covalent.net wrote:
> 
> I am posting a copy of mod_cache.c, which is a VERY simple cache module
> for Apache 2.0.  This basically implements a file cache filter and with
> some work it can be abstracted to other cache types.  The reason I am not
> committing it, is because this is horribly broken right now.  It never
> reads from the cache to try to serve that page, and it always caches to
> the same file.  :-)  The first problem is just a matter of writing a
> handler.  The second is even easier, we need to rip the logic out of the
> current file_cache directory to get a valid key for the file.
> 
> I have added comments for where things should be abstracted so that
> different back-ends can be used.  I don't want this to fall on the floor,
> and if this stays on my hard-drive, it will not see the light of day for
> at least a month.  So, have at it and if anybody wants to pick this up,
> let me know.  I want to help, but I am stretched too thin to do the cache
> myself.  :-)

Normally, I'd say commit it to the experimental/ directory, but it hasn't
even reached an experimental point :-)  [ all the things in there at least
do what they say, even if they might not cover all boundary conditions ]

While I agree with not wanting to lose the work, I think by posting it to
new-httpd we're okay (and Bill's comment that Victor may want to work on
it).

I'm -1 for putting it into the repository until we have a location that
implies "in development; doesn't work".  modules/broken/ ?

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: mod_cache.c

Posted by rb...@covalent.net.
On Wed, 15 Nov 2000, Bill Stoddard wrote:

> Victor has expressed interest in working on this. I'll point him to this list.

Victor and I have already discussed this.  I expect 99% of this
development to happen on modproxy-dev, and only posted to new-httpd as a
curteosy.  :-)  I have suggested to Victor that he co-ordinate with
modproxy-dev, because there are already two other people who have asked
for this module.  In fact, that list is why this module got posted today
instead of me just working on it in my spare time.

Ryan

> > I am posting a copy of mod_cache.c, which is a VERY simple cache module
> > for Apache 2.0.  This basically implements a file cache filter and with
> > some work it can be abstracted to other cache types.  The reason I am not
> > committing it, is because this is horribly broken right now.  It never
> > reads from the cache to try to serve that page, and it always caches to
> > the same file.  :-)  The first problem is just a matter of writing a
> > handler.  The second is even easier, we need to rip the logic out of the
> > current file_cache directory to get a valid key for the file.
> >
> > I have added comments for where things should be abstracted so that
> > different back-ends can be used.  I don't want this to fall on the floor,
> > and if this stays on my hard-drive, it will not see the light of day for
> > at least a month.  So, have at it and if anybody wants to pick this up,
> > let me know.  I want to help, but I am stretched too thin to do the cache
> > myself.  :-)


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: mod_cache.c

Posted by Bill Stoddard <bi...@wstoddard.com>.
Victor has expressed interest in working on this. I'll point him to this list.

Bill
----- Original Message -----
From: <rb...@covalent.net>
To: <ne...@apache.org>; <mo...@apache.org>
Sent: Wednesday, November 15, 2000 9:34 AM
Subject: mod_cache.c


>
> I am posting a copy of mod_cache.c, which is a VERY simple cache module
> for Apache 2.0.  This basically implements a file cache filter and with
> some work it can be abstracted to other cache types.  The reason I am not
> committing it, is because this is horribly broken right now.  It never
> reads from the cache to try to serve that page, and it always caches to
> the same file.  :-)  The first problem is just a matter of writing a
> handler.  The second is even easier, we need to rip the logic out of the
> current file_cache directory to get a valid key for the file.
>
> I have added comments for where things should be abstracted so that
> different back-ends can be used.  I don't want this to fall on the floor,
> and if this stays on my hard-drive, it will not see the light of day for
> at least a month.  So, have at it and if anybody wants to pick this up,
> let me know.  I want to help, but I am stretched too thin to do the cache
> myself.  :-)
>
>
> #include "apr_strings.h"
> #include "ap_config.h"
> #include "util_filter.h"
> #include "httpd.h"
> #include "http_config.h"
> #include "http_request.h"
> #include "http_core.h"
> #include "http_protocol.h"
> #include "http_log.h"
> #include "http_main.h"
> #include "util_script.h"
> #include "http_core.h"
>
> module MODULE_VAR_EXPORT cache_module;
>
> typedef struct cache_struct {
>     char *filename;
>     apr_file_t *fd;
>     int state;
> } cache_struct;
>
> static int cache_filter(ap_filter_t *f, ap_bucket_brigade *bb)
> {
>     cache_struct *ctx;
>     ap_bucket *e;
>
>     if (ctx == NULL) {
>         f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
>     }
>     ctx->state = 1;
>     if (ctx->state) {
>         return ap_pass_brigade(f->next, bb);
>     }
>     if (ctx->filename == NULL) {
>         apr_status_t rv;
>         ctx->filename = ap_server_root_relative(f->r->pool,
"logs/cachefile");
> /* XXX Cache modules should abstract out the open call */
>         if ((rv = apr_open(&ctx->fd, ctx->filename,
>                      APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED,
>                      APR_UREAD | APR_UWRITE, f->r->pool)) != APR_SUCCESS) {
>             ap_log_error(APLOG_MARK, APlOG_ERROR, rv, f->r,
>                          "Could not create cache file");
>             return ap_pass_brigade(f->next, bb);
>         }
>     }
>     AP_BRIGADE_FOREACH(e, bb) {
>         const char *str;
>         apr_ssize_t length;
>
>         ap_bucket_read(e, &str, &length, 0);
> /* XXX Cache modules should abstract out the write call */
>         apr_write(ctx->fd, str, length);
>     }
>     ap_pass_brigade(f->next, bb);
>     return APR_SUCCESS;
> }
>
> static void cache_register_hook(void)
> {
>     ap_register_output_filter("CACHE", cache_filter, AP_FTYPE_HTTP_HEADER);
> }
>
> module MODULE_VAR_EXPORT cache_module = {
>     STANDARD20_MODULE_STUFF,
>     NULL, /* create per-directory config structure */
>     NULL,        /* merge per-directory config structures */
>     NULL, /* create per-server config structure */
>     NULL, /* merge per-server config structures */
>     NULL, /* command apr_table_t */
>     NULL,          /* handlers */
>     cache_register_hook /* register hooks */
> };
>
>
>
______________________________________________________________________________
_
> Ryan Bloom                        rbb@apache.org
> 406 29th St.
> San Francisco, CA 94131
> ----------------------------------------------------------------------------
---
>
>