]> granicus.if.org Git - apache/commitdiff
* Add CacheMinExpire directive to set the minimum time in seconds to cache a document
authorRuediger Pluem <rpluem@apache.org>
Tue, 17 Jan 2006 15:12:23 +0000 (15:12 +0000)
committerRuediger Pluem <rpluem@apache.org>
Tue, 17 Jan 2006 15:12:23 +0000 (15:12 +0000)
  in the case that no valid expire time was supplied with the document.

Submitted by: Brian Akins <brian.akins turner.com>
Reviewed by: Ruediger Pluem

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

CHANGES
docs/manual/mod/mod_cache.xml
modules/cache/mod_cache.c
modules/cache/mod_cache.h

diff --git a/CHANGES b/CHANGES
index af8d7e611bfc2727a4b384bf70c4127d7ef4836a..257eb7ee16b3693738ee2c7d07bf468df247d081 100644 (file)
--- 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 <brian.akins turner.com>, Ruediger Pluem]
+
   *) mod_cache: Make caching of reverse proxies possible again. PR 38017.
      [Ruediger Pluem]
 
index 8ac74c1d2d50030b4a739242db2b05fe347749d4..2193d9db6cfc2b6af69d8d7eb5887cd9cc62b1d2 100644 (file)
@@ -211,6 +211,26 @@ manager</description>
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>CacheMinExpire</name>
+<description>The minimum time in seconds to cache a document</description>
+<syntax>CacheMinExpire <var>seconds</var></syntax>
+<default>CacheMinExpire 0</default>
+<contextlist><context>server config</context><context>virtual host</context>
+</contextlist>
+
+<usage>
+    <p>The <directive>CacheMinExpire</directive> 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.</p>
+
+
+    <example>
+      CacheMinExpire 3600
+    </example>
+</usage>
+</directivesynopsis>
+
 <directivesynopsis>
 <name>CacheDefaultExpire</name>
 <description>The default duration to cache a document when no expiry date is specified.</description>
index c89f50358e0f0669c4797e4e518b0378e68b549f..3d612e1833cd31417c386b163ba7026a6d921cf6 100644 (file)
@@ -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,
index 0e16e19580b2ca7bd1f9310af1309391abf083c3..2ac47dd2bf7796e38907ea6fe6777c57558fc56c 100644 (file)
@@ -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 */