Purge cached content to force the CDN to request a new version of that content from an origin server or Serverless Compute. 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 relative path, surrogate key, or all cached content using the:
By default, deploying to Edgio automatically purges that environment’s cached content. Learn more.
Relative Path
You may specify a relative path that identifies the set of cached respones 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 Developer Console
Use the Edgio Developer console to purge cached content within a specific environment.
To purge content
-
Load the Caching page.
- From the Edgio Developer console, select the desired private or team space.
- 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 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:
1edgio cache-clear --team=my-team --site=my-videos --environment=production --surrogate-key=basketball
REST API
Purge cached content through the Edgio REST API through the clear-cache endpoint. You may purge:
- All content: Exclude the
paths
andsurrogateKeys
properties. - By relative path: Pass the
paths
array of string values. You may use an*
to represent zero or more characters. - By surrogate key: Pass the
surrogateKeys
array of string values. Learn more about surrogate keys.
Deployments
By default, all cached responses are purged from an environment when you deploy a new version of your site. Override this behavior by marking the Preserve cache between deployments setting on the Caching page.
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. Before enabling this feature, 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.
Static prerendering after clearing the cache
If you have enabled static prerendering, the cache will automatically be repopulated when you clear all entries from the cache (such as when you select Purge all entries in the Edgio Developer Console or run edgio cache-clear
without providing --path
or --surrogate-key
). You can view the prerendering progress by clicking on the active deployment for the environment that was cleared.
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”.
1"scripts": {2 ...3 "clearcache:dev": "edgio cache-clear --team=myTeam --site=myEdgioApp --environment=development --token=$edgio_deploy_token",4 "clearcache:stage": "edgio cache-clear --team=myTeam --site=myEdgioApp --environment=staging --token=$edgio_deploy_token",5 "clearcache:prod": "edgio cache-clear --team=myTeam --site=myEdgioApp --environment=production --token=$edgio_deploy_token",6 "clearcache:prod:pdps": "edgio cache-clear --team=myTeam --site=myEdgioApp --environment=production --surrogate-key=pdp --token=$edgio_deploy_token",7 "clearcache:prod:plps": "edgio cache-clear --team=myTeam --site=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
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}}