httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TOKI...@aol.com
Subject Re: Caching handles?
Date Mon, 20 Aug 2001 01:14:11 GMT

>  > Sterling Hughes wrote
>  >
>  > I'm developing a module (httpd2.0) and I've come across a situation
>  > where it would be great if I could "cache" an operation, by saving a
>  > variable in memory, and keep it there throughout requests, ie:

The best place to keep any module specific data 'throughout requests'
is inside the module's own 'config' memory. Just add whatever private
buffer space you want to the module's config structure and don't
publish it. You can then read/write that area across requests from
within your module and use it like a 'cache'.

>  > Is something like this available?  (I don't need a full explanation,
>  > although I wouldn't mind one, just a pointer to the source I should
>  > be looking at...)

Look at the source code for a module called mod_gzip.

It does this very thing. 

The module configuration structure for
mod_gzip has some 'private' data areas in the config which it
uses for 'Item mapping' which is a configurable list of all the
things which may or may not be eligible for IETF Content-Encoding.
mod_gzip can read/write this 'Item mapping' info across requests
if it likes and unless I have totally missed the point this is 
what you are trying to do, yes?

Even if you are writing 2 modules and you want either/or to be
able to access 'cached' data in the other modules memory this
is also no problem with Apache. mod_gzip doesn't really 
'write' any other modules config area but it certainly shows how
easy it is for any module to read any other modules 'config' area.

Other modules do this 'cross-module config memory access'
as well. It's really no big deal.

Actually... just look at mod_proxy. It uses it's config memory
as a 'data cache' as well.

Yours...
Kevin Kiley

In a message dated 01-08-20 00:31:37 EDT, you write:

> The closest thing to what you want to do is probably mod_file_cache.
>  
>  Ryan
>  
>  On Friday 17 August 2001 22:40, Sterling Hughes wrote:
>  > Hi,
>  >
>  >    I'm developing a module (httpd2.0) and I've come across a situation
>  >    where it would be great if I could "cache" an operation, by saving a
>  >    variable in memory, and keep it there throughout requests, ie:
>  >
>  >    /* top level */
>  >    static int module_id;
>  >
>  >    /* in init func */
>  >    module_id = cache_init();
>  >
>  >    /* In some other function */
>  >    cache_storage *p;
>  >    some_type_t   *what_we_want; /* gotta love that variable name :) */
>  >
>  >    if (cache_get(module_id, &p) == SUCCESS) {
>  >        what_we_want = p->data;
>  >    }
>  >    else {
>  >        what_we_want = alloc_new();
>  >        cache_store(module_id, &what_we_want);
>  >    }
>  >
>  >    /* Manipulate what_we_want */
>  >
>  >    Is something like this available?  (I don't need a full explanation,
>  >    although I wouldn't mind one, just a pointer to the source I should
>  >    be looking at...)
>  >
>  >    Thanks,
>  >    Sterling

Mime
View raw message