Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 21077 invoked from network); 23 Aug 2005 13:50:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Aug 2005 13:50:51 -0000 Received: (qmail 28926 invoked by uid 500); 23 Aug 2005 13:50:51 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 28737 invoked by uid 500); 23 Aug 2005 13:50:50 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 28724 invoked by uid 99); 23 Aug 2005 13:50:50 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 23 Aug 2005 06:50:50 -0700 Received: (qmail 21060 invoked by uid 65534); 23 Aug 2005 13:50:50 -0000 Message-ID: <20050823135050.21059.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r239407 - /httpd/httpd/trunk/modules/cache/cache_storage.c Date: Tue, 23 Aug 2005 13:50:49 -0000 To: cvs@httpd.apache.org From: colm@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: colm Date: Tue Aug 23 06:50:47 2005 New Revision: 239407 URL: http://svn.apache.org/viewcvs?rev=239407&view=rev Log: Improve the cache hit/miss ratio by canonicalising the url key. hostname's are matched case-insensitively, port-based vhosts are catered for and the scheme included for future multi-scheme caching compatibility. Modified: httpd/httpd/trunk/modules/cache/cache_storage.c Modified: httpd/httpd/trunk/modules/cache/cache_storage.c URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/modules/cache/cache_storage.c?rev=239407&r1=239406&r2=239407&view=diff ============================================================================== --- httpd/httpd/trunk/modules/cache/cache_storage.c (original) +++ httpd/httpd/trunk/modules/cache/cache_storage.c Tue Aug 23 06:50:47 2005 @@ -320,12 +320,82 @@ apr_status_t cache_generate_key_default(request_rec *r, apr_pool_t* p, char**key) { - if (r->hostname) { - *key = apr_pstrcat(p, r->hostname, r->uri, "?", r->args, NULL); + char *port_str, *scheme, *hn; + const char * hostname; + int i; + + /* Use the canonical name to improve cache hit rate, but only if this is + * not a proxy request. + */ + if (!r->proxyreq) { + /* Use _default_ as the hostname if none present, as in mod_vhost */ + hostname = ap_get_server_name(r); + if (!hostname) { + hostname = "_default_"; + } + } + else if(r->parsed_uri.hostname) { + /* Copy the parsed uri hostname */ + hn = apr_pcalloc(p, strlen(r->parsed_uri.hostname) + 1); + for (i = 0; r->parsed_uri.hostname[i]; i++) { + hn[i] = apr_tolower(r->parsed_uri.hostname[i]); + } + /* const work-around */ + hostname = hn; + } + else { + /* We are a proxied request, with no hostname. Unlikely + * to get very far - but just in case */ + hostname = "_default_"; + } + + /* Copy the scheme, ensuring that it is lower case. If the parsed uri + * contains no string or if this is not a proxy request. + */ + if (r->proxyreq && r->parsed_uri.scheme) { + /* Copy the scheme */ + scheme = apr_pcalloc(p, strlen(r->parsed_uri.scheme) + 1); + for (i = 0; r->parsed_uri.scheme[i]; i++) { + scheme[i] = apr_tolower(r->parsed_uri.scheme[i]); + } } else { - *key = apr_pstrcat(p, r->uri, "?", r->args, NULL); + scheme = "http"; } + + /* If the content is locally generated, use the port-number of the + * current server. Otherwise. copy the URI's port-string (which may be a + * service name). If the URI contains no port-string, use apr-util's + * notion of the default port for that scheme - if available. + */ + if(r->proxyreq) { + if (r->parsed_uri.port_str) { + port_str = apr_pcalloc(p, strlen(r->parsed_uri.port_str) + 2); + port_str[0] = ':'; + for (i = 0; r->parsed_uri.port_str[i]; i++) { + port_str[i + 1] = apr_tolower(r->parsed_uri.port_str[i]); + } + } + else if (apr_uri_port_of_scheme(scheme)) { + port_str = apr_psprintf(p, ":%u", apr_uri_port_of_scheme(scheme)); + } + else { + /* No port string given in the AbsoluteUri, and we have no + * idea what the default port for the scheme is. Leave it + * blank and live with the inefficiency of some extra cached + * entities. + */ + port_str = ""; + } + } + else { + /* Use the server port */ + port_str = apr_psprintf(p, ":%u", ap_get_server_port(r)); + } + + /* Key format is a URI */ + *key = apr_pstrcat(p, scheme, "://", hostname, port_str, + r->parsed_uri.path, "?", r->args, NULL); + return APR_SUCCESS; } -