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
- Open the navigation menu and click Identity & Security. Under Web Application Firewall, click Policies.
-
Click the name of the WAF Policy you want to add a caching rule. The WAF Policy overview appears.
- Click Caching Rules.
- Click Create Caching Rule.
- In the Create Caching Rule dialog box, enter the following:
- Name: A unique name for the access rule.
- 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.
- Cache: Cache the requested content when 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.
- Click Create. The caching rule is added to the Caching Rules list.
- Open the navigation menu and click Identity & Security. Under Web Application Firewall, click Policies.
-
Click the name of the WAF policy you want to edit the Caching Rules for. The WAF policy overview appears.
- Click Caching Rules.
- Select the check box for the caching rule you want to update.
- Select Edit from the Actions drop down menu.
- In the Edit Caching Rule dialog box, make the necessary updates.
- Click Save Changes.
- Open the navigation menu and click Identity & Security. Under Web Application Firewall, click Policies.
- Click the name of the WAF policy where you want to delete a caching rule. The WAF policy overview appears.
- Click Caching Rules.
- Select the check box for the caching rule you want to delete.
- Select Delete from the Actions drop down menu.
- In the confirmation dialog box, click Delete.
- Open the navigation menu and click Identity & Security. Under Web Application Firewall, click Policies.
-
Click the name of the WAF Policy where you want to purge the cache. The WAF Policy overview appears.
- Click Caching Rules.
- Select Purge Cache from the Actions dropdown menu.
- In the Purge Cache dialog box, select the condition and URL address to purge and click Purge.
Using the 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 ofwww.example.com/products
, only HTTP requests forwww.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 fromwww.example.com/products
, all HTTP requests requesting URLs starting withwww.example.com/products
will be cached and subsequent requests will receive content from the cache, including requests forwww.example.com/products/new-product
andwww.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 URLswww.example.com/products/new-product/product-banner.jpg
andwww.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 URLswww.example.com/products/new-product/product-banner/blue.jpg
andwww.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"
]
}