Skip to content

​Purge cache by prefix (URL)

Enterprise customers can instantly purge their cache by URL prefix or path separators in their URL. For an example URL like https://www.example.com/foo/bar/baz/qux.jpg, valid purge requests include:

  • www.example.com
  • www.example.com/foo
  • www.example.com/foo/bar
  • www.example.com/foo/bar/baz
  • www.example.com/foo/bar/baz/qux.jpg

Purging by prefix is useful in different scenarios, such as:

  • Purging everything within a directory.
  • Increasing control over cached objects in a path.
  • Simplifying the number of purge calls sent.
  1. Log in to your Cloudflare dashboard, and select your account and domain.
  2. Select Caching > Configuration.
  3. Under Purge Cache, select Custom Purge. The Custom Purge window appears.
  4. Under Purge by, select Prefix.
  5. Follow the syntax instructions.
    • One prefix per line.
    • Maximum 30 prefixes per API call.
  6. Enter the appropriate value(s) in the text field using the format shown in the example.
  7. Select Purge.

Resulting cache status

Purging by prefix deletes the resource, causing CF-Cache-Status header to show MISS for the subsequent request.

If tiered cache is used, purging by prefix may return EXPIRED, as the lower tier tries to revalidate with the upper tier to reduce load on the latter. Depending on whether the upper tier has the resource or not, and whether the end user is reaching the lower tier or the upper tier, EXPIRED or MISS are returned.

Limitations

There are several limitations regarding purge by prefix:

  • Path separators are limited to 31 for a prefix (example.com/a/b/c/d/e/f/g/h/i/j/k/l/m…).
  • Purge requests are limited to 30 prefixes per request.
  • Purge rate-limits apply.
  • URI query strings & fragments cannot purge by prefix:
    • www.example.com/foo?a=b (query string)
    • www.example.com/foo#bar (fragment)

Purge by prefix normalization

Using purge by prefix normalization, when a purge by prefix request comes into Cloudflare for a normalized URL path, the purge service respects the URL normalization and purges the normalized URL.

How does URL Normalization work

Take the following website as an example: https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg. The table below shows you how Cloudflare’s cache views these paths with normalization on/off.

Request from visitor to EDGE

What Cloudflare cache sees with Normalize Incoming URLs ON

What Cloudflare cache sees with Normalize Incoming URLs OFF

https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpghttps://cloudflare.com/%D8%A7%D9%86%D8%B4%D8%A7%D8%A1-%D9%85%D9%88%D9%82%D8%B9-%D8%A7%D9%84%D9%83%D8%AA%D8%B1%D9%88%D9%86%D9%8A/img_1.jpghttps://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg
https://cloudflare.com/%D8%A7%D9%86%D8%B4%D8%A7%D8%A1-%D9%85%D9%88%D9%82%D8%B9-%D8%A7%D9%84%D9%83%D8%AA%D8%B1%D9%88%D9%86%D9%8A/img_1.jpghttps://cloudflare.com/%D8%A7%D9%86%D8%B4%D8%A7%D8%A1-%D9%85%D9%88%D9%82%D8%B9-%D8%A7%D9%84%D9%83%D8%AA%D8%B1%D9%88%D9%86%D9%8A/img_1.jpghttps://cloudflare.com/%D8%A7%D9%86%D8%B4%D8%A7%D8%A1-%D9%85%D9%88%D9%82%D8%B9-%D8%A7%D9%84%D9%83%D8%AA%D8%B1%D9%88%D9%86%D9%8A/img_1.jpg
https://cloudflare.com/hello/img_1.jpghttps://cloudflare.com/hello/img_1.jpghttps://cloudflare.com/hello/img_1.jpg

As shown above, with URL normalization ON, visitors to the two URLs, https://cloudflare.com/%D8%A7%D9%86%D8%B4%D8%A7%D8%A1-%D9%85%D9%88%D9%82%D8%B9-%D8%A7%D9%84%D9%83%D8%AA%D8%B1%D9%88%D9%86%D9%8A/img_1.jpg and https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg, will be served the same cached asset. Purging https://cloudflare.com/%D8%A7%D9%86%D8%B4%D8%A7%D8%A1-%D9%85%D9%88%D9%82%D8%B9-%D8%A7%D9%84%D9%83%D8%AA%D8%B1%D9%88%D9%86%D9%8A/img_1.jpg will instantly purge that asset for both visitors.