You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2010/06/25 21:22:48 UTC

svn commit: r958093 - /httpd/httpd/trunk/modules/cache/mod_socache_dbm.c

Author: wrowe
Date: Fri Jun 25 19:22:48 2010
New Revision: 958093

URL: http://svn.apache.org/viewvc?rev=958093&view=rev
Log:
Iterator implementations welcome, although mod_socache_memcache will 
never gain one, per documentation in the memcached FAQ.

Modified:
    httpd/httpd/trunk/modules/cache/mod_socache_dbm.c

Modified: httpd/httpd/trunk/modules/cache/mod_socache_dbm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_socache_dbm.c?rev=958093&r1=958092&r2=958093&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_socache_dbm.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_socache_dbm.c Fri Jun 25 19:22:48 2010
@@ -502,12 +502,64 @@ static void socache_dbm_status(ap_socach
     return;
 }
 
-static apr_status_t socache_dbm_iterate(ap_socache_instance_t *instance,
+static apr_status_t socache_dbm_iterate(ap_socache_instance_t *ctx,
                                         server_rec *s,
                                         ap_socache_iterator_t *iterator,
                                         apr_pool_t *pool)
 {
-    return APR_ENOTIMPL;
+    apr_dbm_t *dbm;
+    apr_datum_t dbmkey;
+    apr_datum_t dbmval;
+    apr_time_t expiry;
+    int expired;
+    apr_time_t now;
+    apr_status_t rv;
+
+    /*
+     * make sure the expiration for still not-accessed
+     * socache entries is done only from time to time
+     */
+    now = time(NULL);
+    if ((rv = apr_dbm_open(&dbm, ctx->data_file, APR_DBM_RWCREATE,
+                           DBM_FILE_MODE, ctx->pool)) != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "Cannot open socache DBM file `%s' for "
+                     "iterating", ctx->data_file);
+        return rv;
+    }
+    rv = apr_dbm_firstkey(dbm, &dbmkey);
+    while (rv == APR_SUCCESS && dbmkey.dptr != NULL) {
+        expired = FALSE;
+        apr_dbm_fetch(dbm, dbmkey, &dbmval);
+        if (dbmval.dsize <= sizeof(apr_time_t) || dbmval.dptr == NULL)
+            expired = TRUE;
+        else {
+            memcpy(&expiry, dbmval.dptr, sizeof(apr_time_t));
+            if (expiry <= now)
+                expired = TRUE;
+        }
+        if (!expired) {
+            rv = (*iterator)(ctx, s, (unsigned char *)dbmkey.dptr, dbmkey.dsize,
+                             (unsigned char *)dbmval.dptr + sizeof(apr_time_t),
+                             dbmval.dsize - sizeof(apr_time_t), pool);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s,
+                         "dbm `%s' entry iterated", ctx->data_file);
+            if (rv != APR_SUCCESS)
+                return rv;
+ 
+
+        }
+        rv = apr_dbm_nextkey(dbm, &dbmkey);
+    }
+    apr_dbm_close(dbm);
+
+    if (rv != APR_SUCCESS && rv != APR_EOF) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "Failure reading first/next socache DBM file `%s' record",
+                     ctx->data_file);
+        return rv;
+    }
+    return APR_SUCCESS;
 }
 
 static const ap_socache_provider_t socache_dbm = {