This topic describes the syntax, description, parameters, return values, and examples of cache functions.
set_cache_ttl
This function is described as follows:
- Syntax:
set_cache_ttl(type, ttl)
- Description
You can call this function to set the cache duration for specific resources.
- Parameters
- type
The cache type. Valid values:
path and code
. - ttl
- If the type parameter is set to path, the
ttl
parameter specifies the cache duration for specific resources. The value must be an integer. - If the type parameter is set to code, the
ttl
parameter specifies the cache duration for specific response codes. The value must be a string. - Default unit for the cache duration: seconds.
- If the type parameter is set to path, the
- type
- Return values
This function returns
true
upon a success and returnsfalse
upon a failure. - Examples
if match_re($uri, '^/image') { set_cache_ttl('code', '301=10,302=5') } Note: Set the cache durations for status codes responded to requests to URIs that start with "/image", 10 seconds for status code 301 and 5 seconds for status code 302. if eq(substr($uri, -4, -1), '.mp4') { set_cache_ttl('path', 5) } if match_re($uri, '^/201801/mp4/') { set_cache_ttl('path', 50) } if match_re($uri, '^/201802/flv/') { set_cache_ttl('path', 10) } Note: Set different cache durations for file names or URI paths.