Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions content/cache/how-to/purge-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,122 @@ Example: If you purge `foo.com/bar`, any asset that starts with `foo.com/bar` wi

{{</Aside>}}

### Purge by prefix normalization

Currently, when a purge by prefix request comes into Cloudflare for a normalized URL path, the purge service does not respect the [URL normalization](/rules/normalization/). Cloudflare is changing the purge by prefix functionality so that normalized URLs will be purged as expected. We plan for this change to occur on October 12th, 2022.

#### How does URL Normalization work

As an example of this behavior change, 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](/rules/normalization/).

<table>
<tbody>
<th colspan="5" rowspan="1">
Request from visitor to EDGE
</th>
<th colspan="5" rowspan="1">
What Cloudflare cache sees with Normalize Incoming URLs ON
</th>
<th colspan="5" rowspan="1">
What Cloudflare cache sees with Normalize Incoming URLs OFF
</th>
<tr>
<td colspan="5" rowspan="1">
<code>https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg</code>
</td>
<td colspan="5" rowspan="1">
<code>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</code>
</td>
<td colspan="5" rowspan="1">
<code>https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg</code>
</td>
</tr>
<tr>
<td colspan="5" rowspan="1">
<code>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</code>
</td>
<td colspan="5" rowspan="1">
<code>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</code>
</td>
<td colspan="5" rowspan="1">
<code>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</code>
</td>
</tr>
<tr>
<td colspan="5" rowspan="1">
<code>https://cloudflare.com/hello/img_1.jpg</code>
</td>
<td colspan="5" rowspan="1">
<code>https://cloudflare.com/hello/img_1.jpg</code>
</td>
<td colspan="5" rowspan="1">
<code>https://cloudflare.com/hello/img_1.jpg</code>
</td>
</tr>
</tbody>
</table>

#### Behavior change

If you try to purge by prefix, this will happen:

<table>
<tbody>
<th colspan="5" rowspan="1">
What the user wants to purge
</th>
<th colspan="5" rowspan="1">
What the EDGE purges (current behavior)
</th>
<th colspan="5" rowspan="1">
What the EDGE purges (new behavior)
</th>
<tr>
<td colspan="5" rowspan="1">
<code>clouflare.com/انشاء-موقع-الكتروني/</code>
</td>
<td colspan="5" rowspan="1">
<code>cloudflare.com/انشاء-موقع-الكتروني/</code>
</td>
<td colspan="5" rowspan="1">
<code>cloudflare.com/انشاء-موقع-الكتروني/</code>
</td>
</tr>
<tr>
<td colspan="5" rowspan="1">
<code>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/</code>
</td>
<td colspan="5" rowspan="1">
<code>cloudflare.com/انشاء-موقع-الكتروني/</code>
</td>
<td colspan="5" rowspan="1">
<code>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/</code>
</td>
</tr>
<tr>
<td colspan="5" rowspan="1">
<code>cloudflare.com/hello/</code>
</td>
<td colspan="5" rowspan="1">
<code>cloudflare.com/hello/</code>
</td>
<td colspan="5" rowspan="1">
<code>cloudflare.com/hello/</code>
</td>
</tr>
</tbody>
</table>

This means that if the prefix being purged does not match what Cloudflare’s cache sees purge by prefix will not work, regardless of how the URL looked when it hit the edge. Specifically:

- If the visitor request was for `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`, then currently purge by prefix will not be able to purge this asset because no matter what prefix you try to purge, for instance `cloudflare.com/انشاء-موقع-الكتروني/` or `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`, what will be purged is `cloudflare.com/انشاء-موقع-الكتروني/` which will not match the asset that was cached by the visitor request.

With the new behavior, purging by prefix `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/` will purge the asset cached by the visitor request for `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`.

- Currently, if a visitor request was for `https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg` and URL normalization is **ON**, then currently purge by prefix will not be able to purge this asset since it will be cached as if `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` was requested and, similarly to the first point, we can not purge this with the current behaviour. If, on the other hand, URL normalization is **OFF**, then purging by prefix `cloudflare.com/انشاء-موقع-الكتروني/` will purge `https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg`.

With the new behavior, in order to purge by prefix the asset that was cached by the visitor request `https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg`, you can purge by prefix `cloudflare.com/انشاء-موقع-الكتروني/`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure what this sentence means, but I understood correctly I think it would be easier to read by adding () to that first URL:

With the new behavior, in order to purge by prefix the asset that was cached by the visitor request (`https://cloudflare.com/انشاء-موقع-الكتروني/img_1.jpg`), you can purge by prefix `cloudflare.com/انشاء-موقع-الكتروني/`.


## Purge cache key resources

Purge resources that use Cache Keys via the [Cloudflare API](https://api.cloudflare.com/#zone-purge-files-by-url). If you use [Cloudflare’s Purge by URL](https://api.cloudflare.com/#zone-purge-files-by-url), include the headers and query strings that are in your custom Cache Key.
Expand Down