This adds an optional function that one could use to get basic hit/miss stats from mod_cache. Right now it just does hit or miss, could pass an HTTP status code for various status (stale, error, etc.).

Default function does nothing.

--
Brian Akins
Lead Systems Engineer
CNN Internet Technologies
diff -ru httpd-2.2.0.orig/modules/cache/mod_cache.c 
httpd-2.2.0/modules/cache/mod_cache.c
--- httpd-2.2.0.orig/modules/cache/mod_cache.c  2005-11-10 10:20:05.000000000 
-0500
+++ httpd-2.2.0/modules/cache/mod_cache.c       2006-02-27 14:24:19.000000000 
-0500
@@ -20,7 +20,7 @@
 
 module AP_MODULE_DECLARE_DATA cache_module;
 APR_OPTIONAL_FN_TYPE(ap_cache_generate_key) *cache_generate_key;
-
+APR_OPTIONAL_FN_TYPE(ap_cache_update_stats) *cache_update_stats;
 /* -------------------------------------------------------------- */
 
 
@@ -166,9 +166,12 @@
                          "cache: error returned while checking for cached "
                          "file by %s cache", cache->provider_name);
         }
+        cache_update_stats(r, 0);
         return DECLINED;
     }
 
+    cache_update_stats(r, 1);
+
     /* if we are a lookup, we are exiting soon one way or another; Restore
      * the headers. */
     if (lookup) {
@@ -1112,6 +1115,11 @@
     return NULL;
 }
 
+/*default stats does nothing*/
+static apr_status_t cache_update_stats_default(request_rec *r, int hit) {
+    return APR_SUCCESS;
+}
+
 static int cache_post_config(apr_pool_t *p, apr_pool_t *plog,
                              apr_pool_t *ptemp, server_rec *s)
 {
@@ -1122,6 +1130,10 @@
     if (!cache_generate_key) {
         cache_generate_key = cache_generate_key_default;
     }
+    cache_update_stats= APR_RETRIEVE_OPTIONAL_FN(ap_cache_update_stats);
+    if (!cache_update_stats) {
+        cache_update_stats = cache_update_stats_default;
+    }
     return OK;
 }
 
diff -ru httpd-2.2.0.orig/modules/cache/mod_cache.h 
httpd-2.2.0/modules/cache/mod_cache.h
--- httpd-2.2.0.orig/modules/cache/mod_cache.h  2005-10-03 07:30:06.000000000 
-0400
+++ httpd-2.2.0/modules/cache/mod_cache.h       2006-02-27 14:23:56.000000000 
-0500
@@ -322,6 +322,8 @@
                         ap_cache_generate_key, 
                         (request_rec *r, apr_pool_t*p, char**key ));
 
-
+APR_DECLARE_OPTIONAL_FN(apr_status_t,
+                        ap_cache_update_stats,
+                        (request_rec *r, int hit));
 #endif /*MOD_CACHE_H*/
 /** @} */

Reply via email to