🎉 Introducing Edgio v6 which supports Node.js v16. Learn how to upgrade. 🎉
Edgio
Edgio

Purging

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

  1. Load the Caching page.

    1. From the Edgio Developer console, select the desired private or team space.
    2. Select the desired property.
    3. From the left-hand pane, select the desired environment from under the Environments section.
    4. From the left-hand pane, select Caching.
  2. From the Cache Purge History section, click Purge the Cache.

    purge_the_cache_button
  3. 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.
  4. Click Purge Cache.

  5. 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 --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 and surrogateKeys 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”.

JavaScript
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

YAML
1# Add this file to your project at .github/workflows/clear-cache.yml
2#
3# This GitHub action clears the sites PRODUCTION cache at 09:15AM UTC every day.
4#
5# The schedule syntax is standard cron syntax
6# minute hour day-of-month month day-of-week
7# * * * * *
8#
9# 1.) This example depends on a script being defined in your package.json called clearcache:prod
10#
11# In order for this action to clear your cache, you must create a deploy token from the site settings page
12# in https://edgio.app and configure it as a secret called "edgio_deploy_token" in your repo on GitHub.
13
14name: Clear PRODUCTION cache at 5am
15on:
16 schedule:
17 - cron: '15 9 * * *'
18jobs:
19 clear-the-cache:
20 runs-on: ubuntu-latest
21 steps:
22 - name: Extract branch name
23 shell: bash
24 run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV
25 - uses: actions/checkout@v1
26 - uses: actions/setup-node@v1
27 with:
28 node-version: 14
29 registry-url: https://npm-proxy.fury.io/layer0/
30 - name: Cache node modules
31 uses: actions/cache@v1
32 env:
33 cache-name: cache-node-modules
34 with:
35 path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
36 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 ci
42 - name: Clear cache in production
43 run: npm run clearcache:prod
44 env:
45 edgio_deploy_token: ${{secrets.edgio_deploy_token}}