Purge cached content to force the CDN to request a new version of that content from an origin server or Cloud Functions. This ensures that the latest version of that content is delivered to your clients.
Purging does not delete content from the origin server. A file management tool (e.g., SFTP or rsync) may be used to delete content from an origin server.
Purge by hostname, relative path, surrogate key, or all cached content using the:
By default, deploying to Edgio preserves an environment’s cached content. Learn more.
Hostname
You may purge cached content by the request URL’s hostname. Choose between either of the following options:
-
Purging all cached content for that hostname. Verify that the Purge all entries option is selected and then select the desired hostname from the Hostname option.
-
Purging requests for that hostname and a specific relative path. Select the Purge by path option and then select the desired hostname from the Hostname option.
Relative Path
You may specify a relative path that identifies the set of cached responses that will be purged. This relative path starts directly after the hostname.
Use an
*
to represent zero or more characters.Example:
This example assumes that you need to purge the following content:
https://cdn.example.com/sports/basketball/marchtournament.html
Purge the above URL by specifying the following relative path:
/sports/basketball/marchtournament.html
Alternatively, you can use an
*
to recursively purge a directory. The following relative path pattern recursively purges all content from the /sports
directory including marchtournament.html
:/sports/*
Surrogate Key
You may purge cached content by surrogate key (aka cache tag). A surrogate key is a label that you may apply to cached responses. Purging by surrogate key allows you to purge related content across your entire site.
Improve performance and reduce the load on your web servers by only purging targetted content through the use of surrogate keys.
Tagging Cached Content
Apply a surrogate key by setting the
Surrogate-Key
response header.Syntax:
Surrogate-Key: <TAG1> <TAG2> <TAG3>
Example:
For example, the following response header applies three surrogate keys to the cached response. Purging any of those three surrogate keys will purge all cached responses tagged with that surrogate key.
Surrogate-Key: sports basketball march-tournament
Edgio Console
Use the Edgio Console to purge cached content within a specific environment.
To purge content
-
Load the Caching page.
- From the Edgio Console, select the desired private space or organization.
- Select the desired property.
- From the left-hand pane, select the desired environment from under the Environments section.
- From the left-hand pane, select Caching.
-
From the Cache Purge History section, click Purge the Cache.
-
Purge:
- All Cached Content: Select Purge all entries.
- By Path: Select Purge by path. Specify each desired relative path on a separate line.
- By Hostname: Select Purge all entries and then select the desired hostname from the Hostname option.
- By Hostname for a Specific Path: Select Purge by path, specify the desired relative path(s), and then select the desired hostname from the Hostname option.
- By Surrogate Key: Select Purge by surrogate key. Specify each desired surrogate key on a separate line.
-
Click Purge Cache.
-
When prompted, click Purge to confirm that your content will be purged.
Edgio CLI
Purge cached content through the Edgio CLI by passing the cache-clear argument. You may purge:
- All content: Exclude the
--path
and--surrogate-key
options. - By relative path: Pass the
--path
option. You may use an*
to represent zero or more characters. - By surrogate key: Pass the
--surrogate-key
option. Learn more about surrogate keys.
Example:
Run the following command to purge the
basketball
surrogate key from the production
environment from the my-videos
property:Bash
1edgio cache-clear --organization=my-organization --property=my-videos --environment=production --surrogate-key=basketball
REST API
Purge cached content through the Edgio REST API through the Purge Cache endpoint. You may purge:
- All content: Set the
purge_type
property toall_entries
. - By relative path: Set the
purge_type
property topath
. Pass the desired relative paths through thevalues
array of strings. You may use an*
to represent zero or more characters. - By surrogate key: Set the
purge_type
property tosurrogate_key
. Pass the desired surrogate keys through thevalues
array of strings. Learn more about surrogate keys. - By hostname: Set the
hostname
property to the desired hostname. Purging by hostname is compatible with thepurge_type
property set to eitherall_entries
orpath
.
Deployments
By default, cached content is preserved when you deploy a new version of your site. Override this behavior when deploying changes by marking the Purge the cache after deployment setting on the Deploy Changes popup. The default state for this option is determined by the Caching page’s Automatically purge the cache on deployments option.
While preserving the cache between deployments can greatly reduce the load on your origin following a deployment, it can also lead to inconsistent behavior if the new version of your browser code receives an old, incompatible API response from the cache. If you plan on preserving cache content between deployments, then we recommend adding an API version number to your URL scheme to ensure that breaking changes to your API don’t affect your website’s functionality when old responses are served from the cache.
Automated Purging
Automate cache purging through NPM scripts and GitHub actions.
NPM Scripts
Here is an example script you can add to your
package.json
to handle cache clearing for each environment. You can also configure scripts to clear by surrogate key, path, or group (As defined in Edgio Console)These scripts assume that you have created environments called “production”, “staging”, and “development and you have created a deploy key for your site and added it as a secret in your repo called “edgio_deploy_token”.
JavaScript
1"scripts": {2 ...3 "clearcache:dev": "edgio cache-clear --organization=my-organization --property=myEdgioApp --environment=development --token=$edgio_deploy_token",4 "clearcache:stage": "edgio cache-clear --organization=my-organization --property=myEdgioApp --environment=staging --token=$edgio_deploy_token",5 "clearcache:prod": "edgio cache-clear --organization=my-organization --property=myEdgioApp --environment=production --token=$edgio_deploy_token",6 "clearcache:prod:pdps": "edgio cache-clear --organization=my-organization --property=myEdgioApp --environment=production --surrogate-key=pdp --token=$edgio_deploy_token",7 "clearcache:prod:plps": "edgio cache-clear --organization=my-organization --property=myEdgioApp --environment=production --surrogate-key=plp --token=$edgio_deploy_token",8 ...9 },
GitHub Actions
Here is an example GitHub action that clears the cache at a scheduled time using the jobs defined in your
package.json
YAML
1# Add this file to your project at .github/workflows/clear-cache.yml2#3# This GitHub action clears the sites PRODUCTION cache at 09:15AM UTC every day.4#5# The schedule syntax is standard cron syntax6# minute hour day-of-month month day-of-week7# * * * * *8#9# 1.) This example depends on a script being defined in your package.json called clearcache:prod10#11# In order for this action to clear your cache, you must create a deploy token from the site settings page12# in https://edgio.app and configure it as a secret called "edgio_deploy_token" in your repo on GitHub.1314name: Clear PRODUCTION cache at 5am15on:16 schedule:17 - cron: '15 9 * * *'18jobs:19 clear-the-cache:20 runs-on: ubuntu-latest21 steps:22 - name: Extract branch name23 shell: bash24 run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV25 - uses: actions/checkout@v126 - uses: actions/setup-node@v127 with:28 node-version: 1429 registry-url: https://npm-proxy.fury.io/layer0/30 - name: Cache node modules31 uses: actions/cache@v132 env:33 cache-name: cache-node-modules34 with:35 path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS36 key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}37 restore-keys: |38 ${{ runner.os }}-build-${{ env.cache-name }}-39 ${{ runner.os }}-build-40 ${{ runner.os }}-41 - run: npm ci42 - name: Clear cache in production43 run: npm run clearcache:prod44 env:45 edgio_deploy_token: ${{secrets.edgio_deploy_token}}