提交 023d816c authored 作者: Anthony Minessale's avatar Anthony Minessale

favor the lessor of the configured cache-ttl or the max-age, add an…

favor the lessor of the configured cache-ttl or the max-age, add an abs-cache-ttl to be forced cache ttl, and add cache_ttl and abs_cache_ttl url params to set it per req
上级 5c696f9b
......@@ -295,6 +295,8 @@ CONFIGURATION:
<param name="" value="">
debug : <true|false> false Print debug data
file-cache-ttl : <number of sec> 300 How long to wait before checking the server to see if audio file has changed.
Whichever is smaller that or the max-age returned by the server (if present).
abs-file-cache-ttl : <number of sec> 0 Force the cache time no matter what anything else says.
file-not-found-expires : <number of sec> 300 How long to still preserve cached audio files that are not found by the server.
<profile name="<name>"> : CREATE NEW PROFILE TO REFERENCE BY NAME
......
......@@ -154,6 +154,7 @@ static struct {
int debug;
int not_found_expires;
int cache_ttl;
int abs_cache_ttl;
} globals;
......@@ -1685,6 +1686,14 @@ static switch_status_t do_config(void)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s]for file-cache-ttl\n", val);
}
} else if (!strcasecmp(var, "abs-file-cache-ttl")) {
int tmp = atoi(val);
if (tmp > -1) {
globals.abs_cache_ttl = tmp;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s]for file-cache-ttl\n", val);
}
} else if (!strcasecmp(var, "file-not-found-expires")) {
globals.not_found_expires = atoi(val);
......@@ -2502,17 +2511,39 @@ static switch_status_t write_meta_file(http_file_context_t *context, const char
}
if (!zstr(data)) {
int ttl = globals.cache_ttl;
int ttl = globals.cache_ttl, abs_cache_ttl = globals.abs_cache_ttl;
const char *cc;
const char *p;
int x;
if (context->url_params) {
if ((cc = switch_event_get_header(context->url_params, "abs_cache_control"))) {
x = atoi(cc);
if (headers && (cc = switch_event_get_header(headers, "Cache-Control"))) {
if (x > 0) {
abs_cache_ttl = x;
}
} else if ((cc = switch_event_get_header(context->url_params, "cache_control"))) {
x = atoi(cc);
if (x > 0) {
ttl = x;
}
}
}
if (abs_cache_ttl) {
ttl = abs_cache_ttl;
} else if (headers && (cc = switch_event_get_header(headers, "Cache-Control"))) {
if ((p = switch_stristr("max-age=", cc))) {
p += 8;
if (!zstr(p)) {
ttl = atoi(p);
if (ttl < 0) ttl = globals.cache_ttl;
x = atoi(p);
if (x < ttl) {
ttl = x;
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论