memc_pass
The 'memc_pass' directive sends requests to a specified memcached server for data storage operations.
Description
The 'memc_pass' directive is used to define a memcached backend server where requests will be forwarded. This directive operates in the location and if contexts within an NGINX configuration, allowing significantly flexible routing of requests based on various conditions. When a request is processed, the directive expects memc_key to be set prior to invocation in order to identify the specific cache entry being accessed. Depending on the HTTP method of the incoming request, the directive automatically determines the appropriate memcached command to use, which can include 'get', 'set', 'add', or 'delete'. This dynamic adjustment is crucial for efficiently handling different operations without requiring additional configuration for each command.
This directive requires one argument, which is the address of the memcached server, typically in the form '127.0.0.1:11211'. When the request reaches the memc_pass directive, it creates a connection to the specified memcached server, sending the appropriate command determined by the HTTP method used. If all conditions are met, NGINX processes the response from the memcached server and either retrieves the requested data, stores new data, or performs the deletion as specified by the command. Additionally, the directive works closely with variables defined by the 'ngx_http_memc_module', which enhance the management of cache operations and allow for more granular control of cache behavior based on request parameters.
Config Example
location /cache {
set $memc_key $arg_key;
memc_pass 127.0.0.1:11211;
}Ensure that the 'memc_key' variable is set appropriately before calling 'memc_pass', otherwise the request may fail.
Be wary of using 'memc_pass' with methods that do not match expected memcached commands, such as unsupported HTTP methods.