]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
favor the lessor of the configured cache-ttl or the max-age, add an abs-cache-ttl...
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 23 Apr 2013 20:52:17 +0000 (15:52 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 23 Apr 2013 20:52:17 +0000 (15:52 -0500)
src/mod/applications/mod_httapi/docs/mod_httapi_doc.txt
src/mod/applications/mod_httapi/mod_httapi.c

index 99970d88c934790bcc40a775551103b39cc68c3f..f659db39af54aee645fd77723a63172bcfc2be20 100644 (file)
@@ -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
index e70c95e8a0ce5ded560c86af7c3288a7821d00a1..1bf3626fbafe5b8e5af8cb10c2d503fa2204e8ff 100644 (file)
@@ -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;
+                                       }
                                }
                        }