Commit 93e204af authored by Ruediger Pluem's avatar Ruediger Pluem
Browse files

* 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 <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
parent 035854d0
Loading
Loading
Loading
Loading
+4 −0
Changes for CHANGES: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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]
+20 −0
Changes for docs/manual/mod/mod_cache.xml: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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>
+21 −0
Changes for modules/cache/mod_cache.c: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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,
+4 −0
Changes for modules/cache/mod_cache.h: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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 */