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