All Products
Search
Document Center

API Gateway:cache-control

Last Updated:Jan 13, 2025

The cache-control plug-in can add the Expires and Cache-Control headers to responses based on URL file suffixes. This allows browsers to cache files with specific suffixes, such as jpg and png.

Running attributes

Plug-in execution stage: Authorization. Plug-in execution priority: 200.

Fields

Field

Data type

Required

Default value

Description

suffix

string

No. The suffix to match, such as jpg and png.

To match multiple suffixes, separate suffixes with a vertical bar (|). Example: png|jpg.

If you do not specify this parameter, all suffixes are matched.

-

This parameter specifies the suffix of files to match.

expires

string

Yes. The maximum period of time to cache files for.

If you specify digits as the value, the unit is seconds. For example, to specify a period of 1 hour, you must enter 3600.

epoch and max are supported and

carry the same semantics as in nginx.

-

This parameter specifies the maximum period of time to cache files for.

Configuration examples

  1. Cache files whose suffix is jpg, png, or jpeg for one hour:

    suffix: jpg|png|jpeg
    expires: 3600

    Based on the preceding configuration, the Expires and Cache-Control headers will be added to responses to the following requests to cache matched files for one hour:

    curl http://example.com/test.png
    curl http://exmaple.com/test.jpg
  2. Cache all files until Thu, 31 Dec 2037 23:55:55 GMT:

    expires: max