From: Ruediger Pluem Date: Tue, 17 Jan 2006 15:12:23 +0000 (+0000) Subject: * Add CacheMinExpire directive to set the minimum time in seconds to cache a document X-Git-Tag: 2.3.0~2604 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=395b632269ce5d2ec57b0e10a42fce07310c8616;p=thirdparty%2Fapache%2Fhttpd.git * Add CacheMinExpire directive to set the minimum time in seconds to cache a document in the case that no valid expire time was supplied with the document. Submitted by: Brian Akins Reviewed by: Ruediger Pluem git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@369811 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index af8d7e611bf..257eb7ee16b 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.3.0 [Remove entries to the current 2.0 and 2.2 section below, when backported] + *) mod_cache: Add CacheMinExpire directive to set the minimum time in + seconds to cache a document. + [Brian Akins , Ruediger Pluem] + *) mod_cache: Make caching of reverse proxies possible again. PR 38017. [Ruediger Pluem] diff --git a/docs/manual/mod/mod_cache.xml b/docs/manual/mod/mod_cache.xml index 8ac74c1d2d5..2193d9db6cf 100644 --- a/docs/manual/mod/mod_cache.xml +++ b/docs/manual/mod/mod_cache.xml @@ -211,6 +211,26 @@ manager + +CacheMinExpire +The minimum time in seconds to cache a document +CacheMinExpire seconds +CacheMinExpire 0 +server configvirtual host + + + +

The CacheMinExpire directive specifies the minimum number of + seconds for which cachable HTTP documents will be retained without checking the origin + server. This is only used if no valid expire time was supplied with the document.

+ + + + CacheMinExpire 3600 + +
+
+ CacheDefaultExpire The default duration to cache a document when no expiry date is specified. diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index c89f50358e0..3d612e1833c 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -689,6 +689,9 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) if ((lastmod != APR_DATE_BAD) && (lastmod < date)) { apr_time_t x = (apr_time_t) ((date - lastmod) * conf->factor); + if (x < conf->minex) { + x = conf->minex; + } if (x > conf->maxex) { x = conf->maxex; } @@ -872,6 +875,8 @@ static void * create_cache_config(apr_pool_t *p, server_rec *s) /* maximum time to cache a document */ ps->maxex = DEFAULT_CACHE_MAXEXPIRE; ps->maxex_set = 0; + ps->minex = DEFAULT_CACHE_MINEXPIRE; + ps->minex_set = 0; /* default time to cache a document */ ps->defex = DEFAULT_CACHE_EXPIRE; ps->defex_set = 0; @@ -908,6 +913,7 @@ static void * merge_cache_config(apr_pool_t *p, void *basev, void *overridesv) overrides->cacheenable); /* maximum time to cache a document */ ps->maxex = (overrides->maxex_set == 0) ? base->maxex : overrides->maxex; + ps->minex = (overrides->minex_set == 0) ? base->minex : overrides->minex; /* default time to cache a document */ ps->defex = (overrides->defex_set == 0) ? base->defex : overrides->defex; /* factor used to estimate Expires date from LastModified date */ @@ -1082,6 +1088,19 @@ static const char *set_cache_maxex(cmd_parms *parms, void *dummy, return NULL; } +static const char *set_cache_minex(cmd_parms *parms, void *dummy, + const char *arg) +{ + cache_server_conf *conf; + + conf = + (cache_server_conf *)ap_get_module_config(parms->server->module_config, + &cache_module); + conf->minex = (apr_time_t) (atol(arg) * MSEC_ONE_SEC); + conf->minex_set = 1; + return NULL; +} + static const char *set_cache_defex(cmd_parms *parms, void *dummy, const char *arg) { @@ -1144,6 +1163,8 @@ static const command_rec cache_cmds[] = "A partial URL prefix below which caching is disabled"), AP_INIT_TAKE1("CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF, "The maximum time in seconds to cache a document"), + AP_INIT_TAKE1("CacheMinExpire", set_cache_minex, NULL, RSRC_CONF, + "The minimum time in seconds to cache a document"), AP_INIT_TAKE1("CacheDefaultExpire", set_cache_defex, NULL, RSRC_CONF, "The default time in seconds to cache a document"), AP_INIT_FLAG("CacheIgnoreNoLastMod", set_cache_ignore_no_last_mod, NULL, diff --git a/modules/cache/mod_cache.h b/modules/cache/mod_cache.h index 0e16e19580b..2ac47dd2bf7 100644 --- a/modules/cache/mod_cache.h +++ b/modules/cache/mod_cache.h @@ -84,6 +84,7 @@ #define MSEC_ONE_MIN ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */ #define MSEC_ONE_SEC ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */ #define DEFAULT_CACHE_MAXEXPIRE MSEC_ONE_DAY +#define DEFAULT_CACHE_MINEXPIRE 0 #define DEFAULT_CACHE_EXPIRE MSEC_ONE_HR #define DEFAULT_CACHE_LMFACTOR (0.1) @@ -150,6 +151,9 @@ typedef struct { #define CACHE_IGNORE_HEADERS_SET 1 #define CACHE_IGNORE_HEADERS_UNSET 0 int ignore_headers_set; + /* Minimum time to keep cached files in msecs */ + apr_time_t minex; + int minex_set; } cache_server_conf; /* cache info information */