Caching Resources Policy

Description

Allows caching of API responses in the Gateway to reduce overall traffic to the back-end API. The Resource Caching Policy can cache requests based on their URL path, http method and specific status code.

This is a built-in policy and therefore no plugins need to be installed prior to using it.

Configuration

If you want to cache POST requests you have to enable stateful request payload inspection in your API Implementation.

The configuration parameters for a Caching Resources Policy are:

  • ttl (long) : Number of seconds to cache the response.

  • cachingResourcesSettingsEntries (array of objects) : The list of matching rules representing the resources to be cached.

    • httpMethod (enum) : The HTTP method to be controlled by the rule. Valid values are:

    • pathPattern (string regexp) : A regular expression used to match the REST resource being cached.

    • statusCode (string): Either a single number representing a specific status code or * to cache all status codes.

Sample Configuration

{
  "ttl" : 60,
  "cachingResourcesSettingsEntries" : [
    { "httpMethod" : "GET",  "pathPattern" : "/customers", "statusCode" : "200" },
    { "httpMethod" : "POST", "pathPattern" : "/customers/.*/orders", "statusCode": "*" },
    { "httpMethod" : "*",    "pathPattern" : "/customers/.*/orders/bad_debts", "statusCode": "403" }
  ]
}