Caching increases HTTP response speed, reduces the load on your origin server, and prevents the generation of duplicate responses. You can configure caching options at the API, downstream, and resource levels.
Before you begin
- On the API Definitions page, in the Registered APIs section, click the ellipsis icon () associated with the API configuration you want to configure caching settings for.
- From the menu, select Manage versions.
- In the Version history panel, click the ellipsis icon () associated with the API configuration version you want to configure caching settings for.
- From the list of delivery options, select Caching.
On the Caching
settings page, set the Enable caching switch to
The caching settings that you configure in API Gateway control the caching of your registered API. If this switch is set to Yes, any caching settings that you specified for the hostnames associated with your API in Property Manager do not apply.
In the API caching section, from the
caching menu, select the type of caching that you want to implement.
For your API caching configuration, you can serve the content from the origin and clear any versions from the cache (no store), serve the content from the origin but do not remove cached versions (bypass cache), cache the content, or honor the caching headers from your origin.
The caching settings that you configure at this level apply to all resources within your API. You can later change the caching settings for individual resources.
Do one of these steps:
If... Then... If you selected No store or Bypass cache, then move on to the next step. If you selected any other option, then do these steps:
- In the Max age field, enter
the maximum time for caching content.
A setting of 0 means
no-cache, which forces origin revalidation before serving the content. For the caching options that honor origin headers, this max age is only used when the origin does not specify one.Note: You can specify this parameter in seconds, minutes, hours, or days. In each case, the value must be between 1 and 1000000.
- Optional: To serve expired objects when revalidation with the origin server is not possible, set the Serve stale objects on origin error switch to Yes.
- To set up an automatic refresh of your cached API content, set the Enable cache prefreshing switch to Yes.
- In the Percentage of max age field, enter the percentage of content’s TTL at which the content should be refreshed.
- In the Max age field, enter the maximum time for caching content.
- Optional: Configure HTTP error caching. See Cache HTTP error responses.
- Optional: Configure downstream caching. See Configure downstream caching.
- Optional: Configure cache key query parameters. See Configure cache key query parameters.
- Optional: Configure caching for individual resources. See Configure resource caching.