mod_http_cache allows one to make an HTTP GET request to cache a document and HTTP PUT to store a document. The primary use case is to download and cache audio files from a web server.
mod_http_cache will only respect the max-age cache-control directive to determine when a cached file becomes stale. Use http_remove_cache <url> to force an update if you know the source file on the server is newer than the cached file.
mod_http_cache offers the http_cache:// read and write file interfaces. See these examples for usage.
mod_http_cache offers the http:// and https:// read and write file interfaces if the "enable-file-formats" param is set to true. DO NOT LOAD mod_httapi IF YOU USE THIS PARAM.
mod_http_cache supports GET/PUT to Amazon S3 private buckets and (on FreeSWITCH later than 1.6) Microsoft's Azure Blob Service. See configuration below.
mod_httapi is also available which offers an HTTP read/write file interface.
To use mod_http_cache:
Tell FreeSWITCH to compile in this module by editing modules.conf in /usr/src/freeswitch/trunk and adding:
Now go recompile FreeSWITCH.
Tell FreeSWITCH to actually use the module when running by adding the module to modules.conf.xml in /usr/local/freeswitch/conf/autoload_configs:
For HTTPS support, grab the latest CA certs from http://curl.haxx.se/ca/cacert.pem and install in /usr/local/freeswitch/conf. An older copy is also available in freeswitch/src/mod/applications/mod_http_cache/conf/cacert.pem.
The conf/autoload_configs/http_cache.conf.xml file contains the configuration.
Download a URL to the cache in a background thread. Does not wait for the download to finish.
Download a document to the cache. Returns the name of the cached file suitable for use by FreeSWITCH APPs or "-ERR" on error:
Same as http_get except if the document is missing from the cache or stale, "-ERR download" is returned. i.e. this API call checks the cache only. "-ERR" is returned on all other errors:
PUT a file. This can be used to PUT a file like a session recording to a webserver:
Invalidate a cached file, typically when the source file has been updated. This will force the updated file to be downloaded into the cache.
Empty the cache:
Play a .wav file hosted by a webserver.
While this example below will work, it is probably best to download all the .wav files needed by a call in a background thread early in the call using http_prefetch. Subsequent calls to http_get will then just grab the cached file. That way, delays in downloading will be less likely to cause pauses in playback.
Force download of source file, for example if the file on the server has been updated and the cached file is now invalid.
How to record a .wav file to a webserver
mod_http_cache can record using the http/https/http_cache file formats. The file is PUT when the recording is completed and the file is closed.