]> granicus.if.org Git - apache/commitdiff
Iterator implementations welcome, although mod_socache_memcache will
authorWilliam A. Rowe Jr <wrowe@apache.org>
Fri, 25 Jun 2010 19:22:48 +0000 (19:22 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Fri, 25 Jun 2010 19:22:48 +0000 (19:22 +0000)
never gain one, per documentation in the memcached FAQ.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@958093 13f79535-47bb-0310-9956-ffa450edef68

modules/cache/mod_socache_dbm.c

index 615e81be7a5ac3a7ae754d68192fd8d59519f7e9..0fc302988002713d0592c3f22175becdd6431c6f 100644 (file)
@@ -502,12 +502,64 @@ static void socache_dbm_status(ap_socache_instance_t *ctx, request_rec *r,
     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 = {