HAProxy Enterprise Documentation 10.5
Caching Small Objects
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.)
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
http-request cache-use test
http-response cache-store test
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
if after both
cache-use is not triggered for a request then
cache-store is ignored even if its condition matches on the response).
Next up Customizing the Log Format