10.2. Setup
- To setup a cache, you must define a cache section and use it in a proxy with
- the corresponding http-request and response actions.
10.2.1. Cache section
- Declare a cache section, allocate a shared cache memory named <name>, the
- size of cache is mandatory.
- Define the size in RAM of the cache in megabytes. This size is split in
- blocks of 1kB which are used by the cache entries. Its maximum value is 4095.
- Define the maximum size of the objects to be cached. Must not be greater than
- an half of "total-max-size". If not set, it equals to a 256th of the cache size.
- All objects with sizes larger than "max-object-size" will not be cached.
- Define the maximum expiration duration. The expiration is set has the lowest
- value between the s-maxage or max-age (in this order) directive in the
- Cache-Control response header and this value. The default value is 60
- seconds, which means that you can't cache an object more than 60 seconds by
- default.
10.2.2. Proxy section
http-request cache-use
- Try to deliver a cached object from the cache <name>. This directive is also
- mandatory to store the cache as it calculates the cache hash. If you want to
- use a condition for both storage and delivering that's a good idea to put it
- after this one.
http-response cache-store
- Store an http-response within the cache. The storage of the response headers
- is done at this step, which means you can use others http-response actions
- to modify headers before or after the storage of the response. This action
- is responsible for the setup of the cache storage filter.
Example:
backend bck1
mode http
http-request cache-use foobar
http-response cache-store foobar
server srv1 127.0.0.1:80
cache foobar
total-max-size 4
max-age 240
HAProxy 2.0.14 – Configuration Manual
2020/04/02, willy tarreau