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.

Using the Console

To create a caching rule
  1. Open the navigation menu. Under Governance and Administration, go to Security and click Web Application Firewall.
  2. Click the name of the WAF Policy you want to add a caching rule. The WAF Policy overview appears.

  3. Click Caching Rules.
  4. Click Create Caching Rule.
  5. In the Create Caching Rule dialog box, enter the following:
    • Name: A unique name for the access rule. Avoid entering confidential information.
    • Caching Rule Action: Select one of the following options:
      • Cache: Cache the requested content when criteria of the rule is met.
        • Caching Duration: The duration to cache content for the caching rule.
        • Time Unit: The unit of time for the caching duration.
        • Enable Client Caching: Select this check box to specify the duration to cache content in the user's browser.
      • Bypass Cache: Allow requests to bypass the cache and be directed to the origin when the criteria of the rule is met.
    • Conditions: Select the condition and URL address that must match for the action to be taken. At least one condition must match for the set action to be taken.
  6. Click Create. The caching rule is added to the Caching Rules list.
To edit a caching rule
  1. Open the navigation menu. Under Governance and Administration, go to Security and click Web Application Firewall.
  2. Click the name of the WAF policy you want to edit the Caching Rules for. The WAF policy overview appears.

  3. Click Caching Rules.
  4. Select the check box for the caching rule you want to update.
  5. Select Edit from the Actions drop down menu.
  6. In the Edit Caching Rule dialog box, make the necessary updates.
  7.   Click Save Changes.
To delete a caching rule
  1. Open the navigation menu. Under Governance and Administration, go to Security and click Web Application Firewall.
  2. Click the name of the WAF policy where you want to delete a caching rule. The WAF policy overview appears.
  3. Click Caching Rules.
  4. Select the check box for the caching rule you want to delete.
  5. Select Delete from the Actions drop down menu.
  6. In the confirmation dialog box, click Delete.
To purge the cache
  1. Open the navigation menu. Under Governance and Administration, go to Security and click Web Application Firewall.
  2. Click the name of the WAF Policy where you want to purge the cache. The WAF Policy overview appears.

  3. Click Caching Rules.
  4. Select Purge Cache from the Actions dropdown menu.
  5. In the Purge Cache dialog box, select the condition and URL address to purge and click Purge.

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"
  ]
}