This topic describes the syntax, description, parameters, and return values of cache functions. This topic also provides examples of these functions.

set_cache_ttl

The following table describes the details about this function.
Item Description
Syntax set_cache_ttl(type, ttl)
Description Sets a time-to-live (TTL) value for cached resources.
Parameter
  • type

    The cache type. Valid values: path and code. Data type: character.

  • ttl
    • If the type parameter is set to path, the ttl parameter specifies the TTL value of the specified resources. Data type: numeric.
    • If the type parameter is set to code, the ttl parameter specifies the TTL value of the specified HTTP status codes. Data type: character.
    • Default unit for the TTL value: seconds.
Return value If the function succeeds, true is returned. Otherwise, false is returned.
Example
if match_re($uri, '^/image') {
    set_cache_ttl('code', '301=10,302=5')
}

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
  • For URIs that start with /image, set a TTL value of 10 seconds for the HTTP 301 status code and a TTL value of 5 seconds for the HTTP 302 status code.
  • Set separate TTL values for file names and URIs.