I'm away from my build/test environment, but this is mostly to plant an idea.

Basically it does this:

Upon successful storage of an object, it call the optional ap_cache_storage_notify. a module, if it implements this function, could then use the ap_cache_info function to get info about the cached object.

Example (omitting error checking):

in mod_foo:

apr_status_t foo_storage_notify(request_rec *r) {
    char *data;
    apr_time_t expires;

    ap_cache_info(r, AP_CACHE_INFO_EXPIRES, &expires);
    ap_cache_info(r, AP_CACHE_INFO_DATA, &data);

    /*do something cool with this, like log in database...*/    
        
}

--
Brian Akins
Lead Systems Engineer
CNN Internet Technologies
diff -ru httpd-2.2.0.orig/modules/cache/cache_util.c 
httpd-2.2.0/modules/cache/cache_util.c
--- httpd-2.2.0.orig/modules/cache/cache_util.c 2005-11-10 10:20:05.000000000 
-0500
+++ httpd-2.2.0/modules/cache/cache_util.c      2006-02-27 15:08:36.000000000 
-0500
@@ -576,3 +576,26 @@
     }
     return headers_out;
 }
+
+CACHE_DECLARE(apr_status_t) ap_cache_info(request_rec *r, int wanted, void 
**arg) {
+    cache_request_rec *cache;
+    apr_status_t rv = APR_SUCCESS;
+    
+    cache = (cache_request_rec *) ap_get_module_config(r->request_config,
+                                                       &cache_module);
+
+    if(!cache) { 
+        return APR_EINVAL;
+    }
+    switch(wanted) {
+    case AP_CACHE_INFO_EXPIRES:
+        *arg = &cache->exp;
+        break;
+        /*add other stuff here*/
+    default:
+        rv = cache->provider->object_info(cache->handle, wanted, arg, r->pool);
+        break;
+    }
+
+    return rv;
+}
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 15:23:03.000000000 
-0500
@@ -20,6 +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_storage_notify) *cache_storage_notify;
 
 /* -------------------------------------------------------------- */
 
@@ -350,6 +351,8 @@
             ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, r->server,
                          "cache: Cache provider's store_body failed!");
             ap_remove_output_filter(f);
+        } else {
+            ap_cache_storage_notify(r);
         }
         return ap_pass_brigade(f->next, in);
     }
@@ -805,6 +808,8 @@
         ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, r->server,
                      "cache: store_body failed");
         ap_remove_output_filter(f);
+    } else {
+        cache_storage_notify(r);
     }
 
     return ap_pass_brigade(f->next, in);
@@ -1112,6 +1117,11 @@
     return NULL;
 }
 
+/*default does nothing*/
+static apr_status_t cache_storage_notify(request_rec *r) {
+    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 +1132,10 @@
     if (!cache_generate_key) {
         cache_generate_key = cache_generate_key_default;
     }
+    cache_storage_notify = APR_RETRIEVE_OPTIONAL_FN(ap_cache_storage_notify);
+    if (!cache_storage_notify) {
+        cache_storage_notify = cache_storage_notify_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 15:23:17.000000000 
-0500
@@ -203,6 +203,7 @@
     int (*open_entity) (cache_handle_t *h, request_rec *r,
                            const char *urlkey);
     int (*remove_url) (cache_handle_t *h, apr_pool_t *p);
+    apr_status_t (*object_info) (cache_handle_t *h, int wanted, void**arg,  
apr_pool_t *p);
 } cache_provider;
 
 /* A linked-list of authn providers. */
@@ -274,6 +275,8 @@
                                                         apr_table_t *t,
                                                         server_rec *s);
 
+CACHE_DECLARE(apr_status_t) ap_cache_info(request_rec *r, int wanted, void 
**arg);
+
 /**
  * cache_storage.c
  */
@@ -322,6 +325,12 @@
                         ap_cache_generate_key, 
                         (request_rec *r, apr_pool_t*p, char**key ));
 
+APR_DECLARE_OPTIONAL_FN(apr_status_t, 
+                        ap_cache_storage_notify, 
+                        (request_rec *r));
+
+
+#define AP_CACHE_INFO_EXPIRES 0
 
 #endif /*MOD_CACHE_H*/
 /** @} */
diff -ru httpd-2.2.0.orig/modules/cache/mod_disk_cache.c 
httpd-2.2.0/modules/cache/mod_disk_cache.c
--- httpd-2.2.0.orig/modules/cache/mod_disk_cache.c     2005-11-17 
08:39:15.000000000 -0500
+++ httpd-2.2.0/modules/cache/mod_disk_cache.c  2006-02-27 15:15:54.000000000 
-0500
@@ -62,6 +62,28 @@
 static apr_status_t read_array(request_rec *r, apr_array_header_t* arr,
                                apr_file_t *file);
 
+static apr_status_t object_info(cache_handle_t *h, int wanted, void**arg, 
apr_pool_t *p) {
+    apr_status_t rv = APR_SUCCESS;
+    disk_cache_object_t *dobj;
+    
+    /* Get disk cache object from cache handle */
+    dobj = (disk_cache_object_t *) h->cache_obj->vobj;
+    
+    switch(wanted) {
+    case AP_CACHE_INFO_DATA:
+        *arg = dobj->datafile;
+        break;
+    case AP_CACHE_INFO_HEADER:
+        *arg = dobj->hdrsfile;
+        break;
+    default:
+        rv = APR_ENOTIMPL;
+        break;
+    }
+    
+    return rv;
+}
+
 /*
  * Local static functions
  */
diff -ru httpd-2.2.0.orig/modules/cache/mod_disk_cache.h 
httpd-2.2.0/modules/cache/mod_disk_cache.h
--- httpd-2.2.0.orig/modules/cache/mod_disk_cache.h     2005-09-29 
17:30:30.000000000 -0400
+++ httpd-2.2.0/modules/cache/mod_disk_cache.h  2006-02-27 15:12:13.000000000 
-0500
@@ -92,4 +92,7 @@
     apr_size_t maxfs;            /* maximum file size for cached files */
 } disk_cache_conf;
 
+#define AP_CACHE_INFO_HEADER  1001
+#define AP_CACHE_INFO_DATA    1002
+
 #endif /*MOD_DISK_CACHE_H*/
diff -ru httpd-2.2.0.orig/modules/cache/mod_mem_cache.c 
httpd-2.2.0/modules/cache/mod_mem_cache.c
--- httpd-2.2.0.orig/modules/cache/mod_mem_cache.c      2005-11-10 
10:20:05.000000000 -0500
+++ httpd-2.2.0/modules/cache/mod_mem_cache.c   2006-02-27 15:10:24.000000000 
-0500
@@ -113,6 +113,11 @@
 
 static void cleanup_cache_object(cache_object_t *obj);
 
+static apr_status_t object_info(cache_handle_t *h, int wanted, void**arg,  
apr_pool_t *p) {
+    /*no provider specific info*/
+    return APR_ENOTIMPL;
+}
+
 static long memcache_get_priority(void*a)
 {
     cache_object_t *obj = (cache_object_t *)a;

Reply via email to