Skip to main content

Plugins - Caching

Most Gate plugins need to perform external HTTP calls, which may add a considerable latency to the request.

In many cases the exact same external call would be performed on every request (e.g., to perform token translations), and caching can be used to greatly improve performance.

To achieve that, Gate can use the RFC 7234-style Cache-Control header to automatically cache responses.

Gate's fine-grained configuration capabilities allow you to pick and choose which URLs and plugins are allowed to cache responses, and also allow you to manually overriding the Cache-Control policy for some URLs.

Example usage

GATE_PLUGINS_HTTP_CACHE_<CACHE_CONFIG_NUMBER>_PATTERN=<URL pattern>
GATE_PLUGINS_HTTP_CACHE_<CACHE_CONFIG_NUMBER>_DISABLED=<Cache disabled>
GATE_PLUGINS_HTTP_CACHE_<CACHE_CONFIG_NUMBER>__DISTINGUISH_BY_HEADERS__=<Header Name 1>,<Header Name 2>
GATE_PLUGINS_HTTP_CACHE_<CACHE_CONFIG_NUMBER>__DISTINGUISH_BY_COOKIES__=<Cookie Name 1>,<Cookie Name 2>
GATE_PLUGINS_HTTP_CACHE_<CACHE_CONFIG_NUMBER>__CACHE_CONTROL_OVERRIDE__=<Cache-Control override>
GATE_PLUGINS_HTTP_CACHE_<CACHE_CONFIG_NUMBER>__RESPECT_NON_CACHEABLE_METHODS__=<Respect non-cacheable methods>

GATE_PLUGINS_<PLUGIN NUMBER>_DISABLE_HTTP_CACHING=<PLUGIN_CACHE_DISABLED>

In Environment variables configuration, <CACHE_CONFIG_NUMBER> is the order in which cache configurations are tested.

For each request, Gate will use the first cache config where the URL matches the specified pattern.

where:

  • <URL pattern> (required): A pattern to be matched to the request URL. Multiple cache configs can be specified, and the first matching config is used for each request.

    e.g., * to match any request, https://api.slashid.com/* to match requests to SlashID Access APIs.

  • <Cache disabled> (defaults to false): If true, no caching whatsoever is performed for the matched requests.

  • <Header name #> (defaults to none): If provided, the request headers matching the given values are used to distinguish cached requests.

    Requests are usually distinguished only by method (GET/POST/etc), URL and body.

    e.g., You may want to distinguish based on Authorization, Cookies, SlashID-*, etc

  • <Cookie name #> (defaults to none): If provided, the request cookies matching the given values are used to distinguish cached requests.

    Requests are usually distinguished only by method (GET/POST/etc), URL and body.

  • <Cache-Control override> (defaults to none): Can be used to override the Cache-Control in the response, in case you want to enable caching but don't have control over the server.

    e.g., max-age=600 will cache the response for 10 minutes.

  • <Respect non-cacheable methods> (defaults to false): If true only GET requests are cached, otherwise POST, PUT, etc, are also cached.

    Note that caching all methods is usually a good idea for Gate plugins, but isn't compliant with RFC 7234.

  • <PLUGIN_CACHE_DISABLED> (defaults to false): Disables caching for a specific plugin.