Small object caching is a handy feature for web application acceleration. Its main objective is to offload some of static content delivery from the application servers so they can perform their primary duty - delivering the application.
Objects such as CSS, JS, and icon files are cached in memory. The maximum object size is limited to the value of the global parameter
tune.bufsize (by default,16KB.)
Usage example The following example uses a total of 4 MB of memory (total-max-size setting) to cache files for 240 seconds (max-age):
Objects are cached only if all the following are true:
Total size less than
HTTP response code 200 (status)
Response does not have a vary header (currently, the cache key is fixed to host+uri and cannot be tuned; hence any vary header causes the request to not be cached)
Response has a content-length header and its size + response headers is less than
Response does not have a "Cache-Control: no-cache" header
cache test total-max-size 4 max-age 240 frontend fe_main bind *:80 http-request cache-use test http-response cache-store test default_backend be_main
Any response for the same host name and path gets the response without HAProxy accessing the backends;
<CACHE>appears in the logs instead of the backend server name.
To store or respond only with more restricted conditions, you can add
cache-use is not triggered for a request then
cache-store is ignored even if its condition matches on the response).