Bypass Cache on URL
This guide describes the process of creating a CDN EdgeRule to bypass the cache on a URL pattern match.
In order to create an EdgeRule you will need the site's ID, Stack ID, and scope ID. Please see StackPath IDs Explained for more information on how to retrieve these three IDs.
Creating an EdgeRule
The API call below to the Create an EdgeRule endpoint tells the StackPath platform to create an EdgeRule to bypass the cache based on a specific URL filter.
In this case, we will instruct the CDN not to cache content whose incoming request URL matches the wildcard value, https://domain.com/test/*
.
We're only adding an originPullPolicy
configuration to the scope, but there are numerous other configuration options available to fine-tune your site's CDN delivery. Please expand the configuration object
menu on the link above to see what other configurations are available.
curl --request POST \
--url https://gateway.stackpath.com/cdn/v1/stacks/STACK_ID/sites/SITE_ID/scopes/SCOPE_ID/rules \
--header 'accept: application/json' \
--header 'authorization: Bearer BEARER_TOKEN' \
--header 'content-type: application/json' \
--data '
{
"name": "test rule",
"configuration": {
"originPullPolicy": [
{
"expirePolicy": "DO_NOT_CACHE",
"expireSeconds": 0,
"noCacheBehavior": "spec",
"enabled": true,
"pathFilter": "https://domain.com/test/*"
}
]
}
}'
The request above returns a JSON object containing the result of the rule that was created on the scope:
{
"rule": {
"id": "916c695b-115d-46e8-a874-a601be65aef7",
"name": "test rule",
"slug": "test-rule"
},
"configuration": {
"originPullPolicy": [
{
"id": "4985154720",
"expirePolicy": "DO_NOT_CACHE",
"expireSeconds": 0,
"noCacheBehavior": "spec",
"defaultCacheBehavior": "UNKNOWN",
"enabled": true,
"pathFilter": "https://domain.com/test/*"
}
]
}
}
Your EdgeRule to bypass the cache on URLs that match https://domain.com/test/* is now in place and running on the StackPath platform. Any incoming requests that match the pattern will not be cached by the StackPath CDN.
Updated 5 months ago