* - the default-max-age of the cache
*
*/
-int http_calc_maxage(struct stream *s)
+int http_calc_maxage(struct stream *s, struct cache *cache)
{
struct http_txn *txn = s->txn;
struct hdr_ctx ctx;
int maxage = -1;
- /* TODO: forced maxage configuration */
-
ctx.idx = 0;
/* loop on the Cache-Control values */
if (smaxage > 0)
- return smaxage;
+ return MIN(smaxage, cache->maxage);
if (maxage > 0)
- return maxage;
-
- /* TODO: return default value */
+ return MIN(maxage, cache->maxage);
- return 60;
+ return cache->maxage;
}
struct filter *filter;
struct hdr_ctx ctx;
struct shared_block *first = NULL;
- struct shared_context *shctx = shctx_ptr((struct cache *)rule->arg.act.p[0]);
+ struct cache *cache = (struct cache *)rule->arg.act.p[0];
+ struct shared_context *shctx = shctx_ptr(cache);
struct cache_entry *object;
/* Insert the node later on caching success */
shctx_lock(shctx);
- if (entry_exist((struct cache *)rule->arg.act.p[0], txn->cache_hash)) {
+ if (entry_exist(cache, txn->cache_hash)) {
shctx_unlock(shctx);
if (filter->ctx) {
object->eb.key = 0;
/* store latest value and expiration time */
object->latest_validation = now.tv_sec;
- object->expire = now.tv_sec + http_calc_maxage(s);
-
+ object->expire = now.tv_sec + http_calc_maxage(s, cache);
}
return ACT_RET_CONT;
}
file, linenum, tmp_cache_config->id);
err_code |= ERR_WARN;
}
-
+ tmp_cache_config->maxage = 60;
tmp_cache_config->maxblocks = 0;
}
} else if (strcmp(args[0], "total-max-size") == 0) {
maxsize = atoi(args[1]) * 1024 * 1024 / CACHE_BLOCKSIZE;
tmp_cache_config->maxblocks = maxsize;
+ } else if (strcmp(args[0], "max-age") == 0) {
+ if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
+ err_code |= ERR_ABORT;
+ goto out;
+ }
+
+ if (!*args[1]) {
+ ha_warning("parsing [%s:%d]: '%s' expects an age parameter in seconds.\n",
+ file, linenum, args[0]);
+ err_code |= ERR_WARN;
+ }
+
+ tmp_cache_config->maxage = atoi(args[1]);
} else if (*args[0] != 0) {
ha_alert("parsing [%s:%d] : unknown keyword '%s' in 'cache' section\n", file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;