srcache_buffer

The `srcache_buffer` directive defines the buffer size for caching subrequest responses in NGINX.

Syntaxsrcache_buffer size;
Defaultnone
Contexthttp, server, location, if in location
Arguments1

Description

The srcache_buffer directive is a configuration option used within the ngx_srcache module that specifies the size of the buffer allocated for storing the response of a subrequest used in caching. This directive is particularly effective when you are dealing with caching mechanics that involve subrequests since it allows you to control how much data can be stored in memory for processing responses before they are sent to the client or stored in a cache backend. The parameter passed to the directive should be a value in bytes, and it informs NGINX about the optimal amount of space required to handle response data effectively.

When utilizing the srcache_buffer directive, it can be set at various levels including http, server, location, and within an if block in a location context. This flexibility allows administrators to fine-tune caching strategies based on different application paths or server configurations. For example, different paths may require different buffer sizes depending on the expected payload size and response characteristics. The directive ensures optimal performance by allocating sufficient space for response content, thus reducing the likelihood of buffer overflows or inadequate storage for the data being processed.

Config Example

location /example {
    srcache_buffer 4k;
    srcache_fetch my_cache;
}

Setting the buffer size too low may lead to incomplete data being cached, especially for larger response sizes.

It’s important not to unintentionally set too high a buffer size, as it could negatively impact memory usage and performance for high-traffic locations.

← Back to all directives