Oracle Cloud Infrastructure Documentation

Caching Rules

Caching rules allow you to selectively cache requested content on Oracle Cloud Infrastructure's edge servers, such as web pages or certain file types.

Note

Caching rules are currently only configurable using the WAAS API.

Use the following API operations to create and manage caching rules that can be applied to your WAF configurations:

Available Cache Rules Criteria

The criteria of the caching rule determines if the requested content should be cached.

  • URL_IS - Matches if the concatenation of requested URL path and query is identical to the contents of the value field. For example, if this rule is set to cache the content of www.example.com/products, only HTTP requests for www.example.com/products will cache.
  • URL_STARTS_WITH - Matches if the concatenation of requested URL path and query starts with the contents of the value field. For example, if this rule is set to cache content from www.example.com/products, all HTTP requests requesting URLs starting with www.example.com/products will be cached and subsequent requests will receive content from the cache, including requests for www.example.com/products/new-product and www.example.com/products/old-product.
  • URL_PART_ENDS_WITH - Matches if the concatenation of requested URL path and query ends with the contents of the value field. For example, if the rule is set to cache content from URLs that end with /product.jpg, HTTP requests for the URLs www.example.com/products/new-product/product-banner.jpg and www.example.com/products/old-product/product-banner.jpg will be cached and subsequent requests will receive content from the cache.
  • URL_PART_CONTAINS - Matches if the concatenation of requested URL path and query contains the contents of the value field. If the rule is set to cache content from URLs that contain /product-banner, HTTP requests for the URLs www.example.com/products/new-product/product-banner/blue.jpg and www.example.com/products/new-product/product-banner/red.jpg will be cached and subsequent requests will receive content from the cache.

Available Cache Rule Actions

A caching rule can be set to take one of two available actions when receiving a request:

  • CACHE - Requests matching the criteria of the rule will be cached and subsequent requests will receive content from the cache.
  • BYPASS_CACHE - Requests matching the criteria of the rule will bypass the cache and be directed to the origin.

Cache Duration

Content can be cached for a specified period of time on Oracle Cloud Infrastructure's edge servers or cached locally by the client. The duration is set in the cachingDuration and clientCachingDuration fields, in ISO 8601 extended format.

Example of a Caching Rule

[
  {
    "action": "CACHE",
    "cachingDuration": "PT20M",
    "clientCachingDuration": "PT20M",
    "criteria": [
      {
        "condition": "URL_IS",
        "value": "/path/to-cache"
      }
    ],
    "isClientCachingEnabled": true,
    "name": "Caching Rule 1"
  },
  {
    "action": "BYPASS_CACHE",
    "criteria": [
      {
        "condition": "URL_PART_ENDS_WITH",
        "value": "urp-part-not-to-cache"
      }
    ],
    "isClientCachingEnabled": false,
    "name": "Do not cache"
  }
]

Best Practices

The order the caching rules is specified in are important. The rules are processed in the order they are specified in and the first matching rule will be used when processing a request. It is best to add rules that bypass cache to the top of the order and caching rules below any bypass rules.

Purge Caches

Caches can be purged using the PurgeCache operation. Caches can either be selectively purged by specifying the URL path of a resource or all caches can be purged for the WAF by not specifying any resources to pass to the API.

Examples

Purge the cache for specified resources:

{
  "resources": [
    "/path/to-purge",
    "/multiple-paths"
  ]
}