Brian Akins wrote: > Paul Querna wrote: > >> CacheEnable disk / > > Maybe have it as an option to CacheEnable instead? > > CacheEnable disk /special_stuff normal > CacheEnable disk / quick > > with quick being the default. That way, you would not have to do it > globally, but could be more specific. > > > Also, have the "both" option where it will try in quick and normal > handlers.
Attached is a patch that adds 'normal', 'both' and 'quick' to the CacheEnable command. It looks okay locally, but I haven't done extensive testing. FWIW, the last night's patch went live on update.mozilla.org, and survived the morning release of Firefox 1.0.4. Little propaganda on 2.1... Basic Setup is two reverse proxy + cache machines in front of a single PHP based Application Server. Both cache/proxies were running Worker MPM and 2.1.3+patches. Peaked at about concurrent 3800 connections each. (only 4 gigs of ram on those machines) Once everything was configured correctly, the machines were not even breaking a sweat. Previously they were using several Squids, but the features in 2.1 are very compelling for their uses... -Paul
Index: modules/cache/cache_util.c =================================================================== --- modules/cache/cache_util.c (revision 169788) +++ modules/cache/cache_util.c (working copy) @@ -27,7 +27,8 @@ CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf *conf, - const char *url) + const char *url, + int htype) { cache_provider_list *providers = NULL; int i; @@ -40,7 +41,9 @@ for (i = 0; i < conf->cacheenable->nelts; i++) { struct cache_enable *ent = (struct cache_enable *)conf->cacheenable->elts; - if ((ent[i].url) && !strncasecmp(url, ent[i].url, ent[i].urllen)) { + if ((ent[i].url) && !strncasecmp(url, ent[i].url, ent[i].urllen) && + (CACHE_HANDLER_BOTH == ent[i].handler_type || + htype == ent[i].handler_type)) { /* Fetch from global config and add to the list. */ cache_provider *provider; provider = ap_lookup_provider(CACHE_PROVIDER_GROUP, ent[i].type, Index: modules/cache/mod_cache.c =================================================================== --- modules/cache/mod_cache.c (revision 169788) +++ modules/cache/mod_cache.c (working copy) @@ -45,7 +45,7 @@ * oh well. */ -static int cache_url_handler(request_rec *r, int lookup) +static int cache_url_real_handler(request_rec *r, int lookup, int htype) { apr_status_t rv; const char *auth; @@ -74,7 +74,7 @@ /* * Which cache module (if any) should handle this request? */ - if (!(providers = ap_cache_get_providers(r, conf, path))) { + if (!(providers = ap_cache_get_providers(r, conf, path, htype))) { return DECLINED; } @@ -156,9 +156,12 @@ /* We are in the quick handler hook, which means that no output * filters have been set. So lets run the insert_filter hook. */ - ap_run_insert_filter(r); + if (htype == CACHE_HANDLER_QUICK) { + ap_run_insert_filter(r); + } + ap_add_output_filter_handle(cache_out_filter_handle, NULL, - r, r->connection); + r, r->connection); /* kick off the filter stack */ out = apr_brigade_create(r->pool, r->connection->bucket_alloc); @@ -174,6 +177,17 @@ return OK; } +static int cache_url_quick_handler(request_rec *r, int lookup) +{ + return cache_url_real_handler(r, lookup, CACHE_HANDLER_QUICK); +} + +static int cache_url_late_handler(request_rec *r) +{ + return cache_url_real_handler(r, 0, CACHE_HANDLER_NORMAL); +} + + /* * CACHE_OUT filter * ---------------- @@ -872,10 +886,12 @@ static const char *add_cache_enable(cmd_parms *parms, void *dummy, const char *type, - const char *url) + const char *url, + const char *handler) { cache_server_conf *conf; struct cache_enable *new; + int htype; if (*type == '/') { return apr_psprintf(parms->pool, @@ -883,6 +899,24 @@ type); } + if (!handler) { + htype = CACHE_HANDLER_QUICK; + } + else if (!strncasecmp(handler, "quick", 5)) { + htype = CACHE_HANDLER_QUICK; + } + else if (!strncasecmp(handler, "both", 4)) { + htype = CACHE_HANDLER_BOTH; + } + else if (!strncasecmp(handler, "normal", 6)) { + htype = CACHE_HANDLER_NORMAL; + } + else { + return apr_psprintf(parms->pool, + "CacheEnable: Invalid handler type: '%s'", + handler); + } + conf = (cache_server_conf *)ap_get_module_config(parms->server->module_config, &cache_module); @@ -890,6 +924,7 @@ new->type = type; new->url = url; new->urllen = strlen(url); + new->handler_type = htype; return NULL; } @@ -975,9 +1010,9 @@ * This is more intuitive that requiring a LoadModule directive. */ - AP_INIT_TAKE2("CacheEnable", add_cache_enable, NULL, RSRC_CONF, - "A cache type and partial URL prefix below which " - "caching is enabled"), + AP_INIT_TAKE23("CacheEnable", add_cache_enable, NULL, RSRC_CONF, + "A cache type and partial URL prefix below which " + "caching is enabled"), AP_INIT_TAKE1("CacheDisable", add_cache_disable, NULL, RSRC_CONF, "A partial URL prefix below which caching is disabled"), AP_INIT_TAKE1("CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF, @@ -1007,9 +1042,12 @@ static void register_hooks(apr_pool_t *p) { - /* cache initializer */ - /* cache handler */ - ap_hook_quick_handler(cache_url_handler, NULL, NULL, APR_HOOK_FIRST); + /* cache handlers */ + ap_hook_quick_handler(cache_url_quick_handler, NULL, NULL, + APR_HOOK_FIRST); + ap_hook_handler(cache_url_late_handler, NULL, NULL, + APR_HOOK_REALLY_FIRST); + /* cache filters * XXX The cache filters need to run right after the handlers and before * any other filters. Consider creating AP_FTYPE_CACHE for this purpose. @@ -1030,6 +1068,8 @@ cache_out_filter, NULL, AP_FTYPE_CONTENT_SET-1); + + /* cache initializer */ ap_hook_post_config(cache_post_config, NULL, NULL, APR_HOOK_REALLY_FIRST); } Index: modules/cache/mod_cache.h =================================================================== --- modules/cache/mod_cache.h (revision 169788) +++ modules/cache/mod_cache.h (working copy) @@ -103,10 +103,15 @@ #define CACHE_DECLARE_DATA __declspec(dllimport) #endif +#define CACHE_HANDLER_NORMAL 0 +#define CACHE_HANDLER_QUICK 1 +#define CACHE_HANDLER_BOTH 2 + struct cache_enable { const char *url; const char *type; apr_size_t urllen; + int handler_type; }; struct cache_disable { @@ -256,7 +261,7 @@ CACHE_DECLARE(char *) generate_name(apr_pool_t *p, int dirlevels, int dirlength, const char *name); -CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf *conf, const char *url); +CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf *conf, const char *url, int is_quick); CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list, const char *key, char **val); CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);