uwsgi_cache_key

The `uwsgi_cache_key` directive sets the key for the cache in NGINX when using uWSGI caching.

Syntaxuwsgi_cache_key string;
Default$request_uri;
Contexthttp, server, location
Arguments1

Description

The uwsgi_cache_key directive is utilized to define a custom key that NGINX will use to store responses in the uWSGI cache. This directive can be essential in scenarios where the cache needs to be segmented based on certain parameters such as session IDs, user authentication states, or any other variable that impacts the content served for a given request. By default, NGINX would use a hash of the request URI, but with this directive, you can explicitly specify how the cache key should be constructed.

The directive works by allowing a single argument, which is a string that can include variables, constants, or both, thereby offering a flexible way to build the caching key. For instance, you might want to include the variable $http_cookie if you want different cache entries based on user sessions. The key defined here is critical for ensuring that cache entries are hit accurately, ensuring the expected responses are retrieved when the same request is made subsequently.

Config Example

uwsgi_cache_key "$scheme$request_method$host$request_uri$http_cookie";

Overriding the default key requires accurate specifications to avoid cache misses.

If using variables in the key, ensure they are defined in the context where the cache is accessed.

← Back to all directives