Browser Cache Control
Function Description
The cache-control plugin implements adding Expires and Cache-Control headers to the response based on the URL file extensions, making it easier for the browser to cache files with specific extensions, such as jpg, png, and other image files.
Runtime Attributes
Plugin execution phase: Authentication Phase
Plugin execution priority: 420
Configuration Fields
| Name | Data Type | Requirements | Default Value | Description |
|---|---|---|---|---|
| suffix | string | Optional, indicates the file extensions to match, such as jpg, png, etc.If multiple extensions are needed, separate them with |, for example png|jpg.If not specified, it matches all extensions. | - | Configures the request file extensions to match |
| expires | string | Required, indicates the maximum caching time. When the input string is a number, the unit is seconds; for example, if you want to cache for 1 hour, enter 3600. You can also enter epoch or max , with the same semantics as in nginx. | - | Configures the maximum caching time |
Configuration Example
- Cache files with extensions
jpg,png,jpeg, with a caching time of one hour
suffix: jpg|png|jpegexpires: 3600With this configuration, the following requests will have Expires and Cache-Control fields added to the response headers, with an expiration time of 1 hour later.
curl http://example.com/test.pngcurl http://example.com/test.jpg- Cache all files, with a maximum caching time of
"Thu, 31 Dec 2037 23:55:55 GMT"
expires: max