Purge static content on the fly

Cache tag headers are typically set at the origin, which means that you have no (or less) flexibility of your content. With tag purging, there are many interesting use cases for static objects. For example, you can control all images uploaded by user X and all images linked to product Y.

In this example, a website has 240.000 different images, each with multiple variants. The URL/filename pattern for the image (ID 122978) is as follows:
  • https://www.scalemates.com/products/img/7/2/9/122978-10911-pristine.jpg
  • https://www.scalemates.com/products/img/7/2/9/122978-10911-540.jpg
  • https://www.scalemates.com/products/img/7/2/9/122978-10911-360.jpg
  • https://www.scalemates.com/products/img/7/2/9/122978-10911-t280.jpg
  • https://www.scalemates.com/products/img/7/2/9/122978-10911-t210.jpg
  • https://www.scalemates.com/products/img/7/2/9/122978-10911-t140.jpg

Use the following steps to set up a cache tag for the above example. You’ll create a variable (PMUSER_CACHE_TAG) to store the cache tag, assign a name for the cache tag ( products-img-{{ID}}=products-img-122978), use the filename (built in variable) and a regex to extract the first digits. Each time the image changes on the website, all of the variants are purged.

How to

  1. Go to > CDN > Properties.
  2. Locate the property where you’re adding the cache tag.
  3. Create a variable named PMUSER_CACHE_TAG to store the calculated cache tag.
  4. Add the Set Variable behavior to the property configuration (see setting behaviors).
  5. Enter the following values, then click Save. For more information, see variable support.
    • Create Value From: Expression
    • Expression (variable support): {{builtin.AK_FILENAME}} (see built-in variables)
    • Operation: Substitute
    • Regex: ^(\d*)-.*
    • Replacement: $1
  6. Add the Modify Incoming Response Header behavior to the property configuration.
  7. Enter the following values, then click Save. For more information, see behaviors that support variables.
    • Action: Modify
    • Select Header Name: Other
    • Custom Header Name (variable support): Edge-Cache-Tag
    • Header Value (variable support): products-img-{{ID}}=products-img-122978