From 6782a1f9fe20b42b769cf990fbea6650778fa2ef Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Fri, 25 Jun 2010 19:22:48 +0000 Subject: [PATCH] Iterator implementations welcome, although mod_socache_memcache will 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 | 56 +++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/modules/cache/mod_socache_dbm.c b/modules/cache/mod_socache_dbm.c index 615e81be7a..0fc3029880 100644 --- a/modules/cache/mod_socache_dbm.c +++ b/modules/cache/mod_socache_dbm.c @@ -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 = { -- 2.40.0