Vote in STATUS: mod_cache lazy initialization
This patch eliminates sconf and scache variables and defers initialization of
conf,
cache and cc_out till they are needed. Saves a few cycles for responses that
cannot
be cached.
I am interested in porting this to 2.0 just to keep mod_cache insync with 2.1
Bill
Index: mod_cache.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/experimental/mod_cache.c,v
retrieving revision 1.64.2.2
diff -u -r1.64.2.2 mod_cache.c
--- mod_cache.c 17 Dec 2002 17:10:05 -0000 1.64.2.2
+++ mod_cache.c 17 Dec 2002 17:46:33 -0000
@@ -418,23 +418,16 @@
{
int rv;
request_rec *r = f->r;
+ cache_request_rec *cache;
+ cache_server_conf *conf;
char *url = r->unparsed_uri;
- const char *cc_out = apr_table_get(r->headers_out, "Cache-Control");
+ const char *cc_out;
const char *exps, *lastmods, *dates, *etag;
apr_time_t exp, date, lastmod, now;
apr_off_t size;
cache_info *info;
- void *sconf = r->server->module_config;
- cache_server_conf *conf =
- (cache_server_conf *) ap_get_module_config(sconf, &cache_module);
- void *scache = r->request_config;
- cache_request_rec *cache =
- (cache_request_rec *) ap_get_module_config(scache, &cache_module);
- apr_bucket *split_point = NULL;
-
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, f->r->server,
- "cache: running CACHE_IN filter");
+ apr_bucket *split_point = NULL;
/* check first whether running this filter has any point or not */
if(r->no_cache) {
@@ -442,10 +435,11 @@
return ap_pass_brigade(f->next, in);
}
- /* make space for the per request config
- * We hit this code path when CACHE_IN has been installed by someone
- * other than the cache handler
- */
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "cache: running CACHE_IN filter");
+
+ /* Setup cache_request_rec */
+ cache = (cache_request_rec *) ap_get_module_config(r->request_config,
&cache_module);
if (!cache) {
cache = apr_pcalloc(r->pool, sizeof(cache_request_rec));
ap_set_module_config(r->request_config, &cache_module, cache);
@@ -516,8 +510,10 @@
lastmod = APR_DATE_BAD;
}
- /* read the etag from the entity */
+ conf = (cache_server_conf *)
ap_get_module_config(r->server->module_config, &cache_module);
+ /* read the etag and cache-control from the entity */
etag = apr_table_get(r->headers_out, "Etag");
+ cc_out = apr_table_get(r->headers_out, "Cache-Control");
/*
* what responses should we not cache?