Jan Kaluza 3f84aef
diff --git a/modules/cache/cache_util.h b/modules/cache/cache_util.h
Jan Kaluza 3f84aef
index eec38f3..1a2d5ee 100644
Jan Kaluza 3f84aef
--- a/modules/cache/cache_util.h
Jan Kaluza 3f84aef
+++ b/modules/cache/cache_util.h
Jan Kaluza 3f84aef
@@ -194,6 +194,9 @@ typedef struct {
Jan Kaluza 3f84aef
     unsigned int store_nostore_set:1;
Jan Kaluza 3f84aef
     unsigned int enable_set:1;
Jan Kaluza 3f84aef
     unsigned int disable_set:1;
Jan Kaluza 3f84aef
+    /* treat maxex as hard limit */
Jan Kaluza 3f84aef
+    unsigned int hardmaxex:1;
Jan Kaluza 3f84aef
+    unsigned int hardmaxex_set:1;
Jan Kaluza 3f84aef
 } cache_dir_conf;
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
 /* A linked-list of authn providers. */
Jan Kaluza 3f84aef
diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c
Jan Kaluza 3f84aef
index 4f2d3e0..30c88f4 100644
Jan Kaluza 3f84aef
--- a/modules/cache/mod_cache.c
Jan Kaluza 3f84aef
+++ b/modules/cache/mod_cache.c
Jan Kaluza 3f84aef
@@ -1299,6 +1299,11 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
Jan Kaluza 3f84aef
             exp = date + dconf->defex;
Jan Kaluza 3f84aef
         }
Jan Kaluza 3f84aef
     }
Jan Kaluza 3f84aef
+    /* else, forcibly cap the expiry date if required */
Jan Kaluza 3f84aef
+    else if (dconf->hardmaxex && (date + dconf->maxex) < exp) {
Jan Kaluza 3f84aef
+        exp = date + dconf->maxex;
Jan Kaluza 3f84aef
+    }        
Jan Kaluza 3f84aef
+
Jan Kaluza 3f84aef
     info->expire = exp;
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
     /* We found a stale entry which wasn't really stale. */
Jan Kaluza 3f84aef
@@ -1717,7 +1722,9 @@ static void *create_dir_config(apr_pool_t *p, char *dummy)
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
     /* array of providers for this URL space */
Jan Kaluza 3f84aef
     dconf->cacheenable = apr_array_make(p, 10, sizeof(struct cache_enable));
Jan Kaluza 3f84aef
-
Jan Kaluza 3f84aef
+    /* flag; treat maxex as hard limit */
Jan Kaluza 3f84aef
+    dconf->hardmaxex = 0;
Jan Kaluza 3f84aef
+    dconf->hardmaxex_set = 0;
Jan Kaluza 3f84aef
     return dconf;
Jan Kaluza 3f84aef
 }
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
@@ -1767,7 +1774,10 @@ static void *merge_dir_config(apr_pool_t *p, void *basev, void *addv) {
Jan Kaluza 3f84aef
     new->enable_set = add->enable_set || base->enable_set;
Jan Kaluza 3f84aef
     new->disable = (add->disable_set == 0) ? base->disable : add->disable;
Jan Kaluza 3f84aef
     new->disable_set = add->disable_set || base->disable_set;
Jan Kaluza 3f84aef
-
Jan Kaluza 3f84aef
+    new->hardmaxex = 
Jan Kaluza 3f84aef
+        (add->hardmaxex_set == 0)
Jan Kaluza 3f84aef
+        ? base->hardmaxex
Jan Kaluza 3f84aef
+        : add->hardmaxex;
Jan Kaluza 3f84aef
     return new;
Jan Kaluza 3f84aef
 }
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
@@ -2096,12 +2106,18 @@ static const char *add_cache_disable(cmd_parms *parms, void *dummy,
Jan Kaluza 3f84aef
 }
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
 static const char *set_cache_maxex(cmd_parms *parms, void *dummy,
Jan Kaluza 3f84aef
-                                   const char *arg)
Jan Kaluza 3f84aef
+                                   const char *arg, const char *hard)
Jan Kaluza 3f84aef
 {
Jan Kaluza 3f84aef
     cache_dir_conf *dconf = (cache_dir_conf *)dummy;
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
     dconf->maxex = (apr_time_t) (atol(arg) * MSEC_ONE_SEC);
Jan Kaluza 3f84aef
     dconf->maxex_set = 1;
Jan Kaluza 3f84aef
+    
Jan Kaluza 3f84aef
+    if (hard && strcasecmp(hard, "hard") == 0) {
Jan Kaluza 3f84aef
+        dconf->hardmaxex = 1;
Jan Kaluza 3f84aef
+        dconf->hardmaxex_set = 1;
Jan Kaluza 3f84aef
+    }
Jan Kaluza 3f84aef
+
Jan Kaluza 3f84aef
     return NULL;
Jan Kaluza 3f84aef
 }
Jan Kaluza 3f84aef
 
Jan Kaluza 3f84aef
@@ -2309,7 +2325,7 @@ static const command_rec cache_cmds[] =
Jan Kaluza 3f84aef
                    "caching is enabled"),
Jan Kaluza 3f84aef
     AP_INIT_TAKE1("CacheDisable", add_cache_disable, NULL, RSRC_CONF|ACCESS_CONF,
Jan Kaluza 3f84aef
                   "A partial URL prefix below which caching is disabled"),
Jan Kaluza 3f84aef
-    AP_INIT_TAKE1("CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF|ACCESS_CONF,
Jan Kaluza 3f84aef
+    AP_INIT_TAKE12("CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF|ACCESS_CONF,
Jan Kaluza 3f84aef
                   "The maximum time in seconds to cache a document"),
Jan Kaluza 3f84aef
     AP_INIT_TAKE1("CacheMinExpire", set_cache_minex, NULL, RSRC_CONF|ACCESS_CONF,
Jan Kaluza 3f84aef
                   "The minimum time in seconds to cache a document"),