# CDN Purge Cache

## Overview <a href="#tong-quan" id="tong-quan"></a>

**CDN Purge Cache** is used in cases where it is necessary to refresh or delete cached content on the CDN system.

Here is a detailed description of the steps to perform Purge Cache on CDN:

* **Step 1:** First, you have initialized an **Object Download** on the vCDN system. For detailed steps, please refer here [.](https://docs-vngcloud-vn.translate.goog/vng-cloud-document/vn/vcdn/loai-hinh-dich-vu/object-download) Suppose, below I have initialized an Object Download *tuongtk3-download* (vCDN Domain: *tuleemu0l7obj.vcdn. cloud* ) and linked it to S3 Origin. On S3 Origin, I have created files demo1.txt ... demo5.txt, text1.txt ... text5.txt.
* **Step 2:** Perform the Purge Cache By (ALL, BEGIN, END, CONTAIN, URI(s) ) test. In which:
  * **ALL** : Clear all cache.
  * **BEGIN** : Clear cache for URLs starting with a certain string.
  * **END** : Clear cache for URLs ending with a certain string.
  * **CONTAINS** : Clear cache for URLs containing a specific string.
  * **URI(s)** : Clear the cache for one or more specific URIs.
* **Step 3:** Call the links for CDN to cache
  * With vCDN Domain: *tuleemu0l7obj.vcdn. cloud* , you can make calls to the links for CDN to cache as follows:
    * <https://tuleemu0l7obj.vcdn.cloud/purge_lab/text1.txt>
    * <https://tuleemu0l7obj.vcdn.cloud/purge_lab/demo1.txt>
    * ....

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-123f40dbc3fa555468dbbaa1b46b7ed527835489%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* When CDN has cached we will see the header `X-Cache: HIT` and `X-Cache-Version: $Thời_gian_timestamp_lưu_cache`in CDN

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-cffd98c62be9690504186d9039ba56200dc556b7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* For files that are not cached in CDN the header will be in the form `X-Cache: MISS`and `X-Cache-Version: $Thời_gian_ timestamp_lưu_cache`in CDN

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-955e2fc42d82df3ae7b7e8a2b2c5cf1c94fd049b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

For details of each type, please refer to the instructions below:

## Detail <a href="#chi-tiet" id="chi-tiet"></a>

### 1. Purge Cache By ALL. <a href="#id-1.-purge-cache-by-all" id="id-1.-purge-cache-by-all"></a>

Purge by ALL: will delete all links (all Cache of resources on CDN).

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-6ea9d3e61724f4ef89440ba1186b0ff6b255ee8a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* Before Purge Cache the files were cached in CDN

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-23497673cb33d9b959d5957e984fcd7fe1179b0d%2Fimage%20(354).png?alt=media" alt=""><figcaption></figcaption></figure>

* Change the contents of the files, then refresh the browser. Because the files have been cached in CDN, when changing in Origin, the files in CDN have not been changed.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-9a5a8093a02aca5707af826d9483a63c3c6535cb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* Proceed to Purge Cache: Select the corresponding **Service** and **CDN and Purge by ALL**

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-b5dd66eb0e8d093b6fb07a53cc383c6685bb993e%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* After Purge cache CDN calls back to Origin to get the latest content.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-4c87c1efda495f8aa4ade1e3489773dbbe8b8578%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### 2. Purge Cache By BEGIN <a href="#id-2.-purge-cache-by-begin" id="id-2.-purge-cache-by-begin"></a>

Purge by BEGIN: Will delete all resources currently cached in CDN starting with the entered character.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-027fe7b0b28434be8f5a732e37a30b94d461113b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* Similar to Purge by ALL, before Purge Cache, the files have been cached in CDN. Proceed to Purge Cache: Select **Service** and corresponding **CDN and Purge by BEGIN** . At URI enter: `/purge_lab/text*`(delete cache of all text\* files in vCDN).

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-a29364a7cd7dd490ec079d4d2607c5f72ae3a02d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* After Purge the file `/purge_lab/text*`is checked and called back to Origin to get the latest content.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-bc837d0d1281231f2225612f2e1afb45ec75e58d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* Since the files `/purge_lab/demo*`are not purged, the content is still fetched from the CDN Cache.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-6e82d2ee38158d9118a0db6352e3d8f4bb5d974c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### 3. Purge Cache By CONTAIN <a href="#id-3.-purge-cache-by-contain" id="id-3.-purge-cache-by-contain"></a>

Purge by CONTAIN: Will delete all resources currently cached in CDN that contain the entered string.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-8a615b2cf17a6fe04959c95cb59627ca40a8f5a4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* Similar to Purge by ALL, before Purge Cache, the files have been cached in CDN. Proceed to Purge Cache: Select **Service** and corresponding **CDN and Purge by CONTAIN** . At URI enter: `/*demo*` (clear cache of all \*demo\* files currently cached in vCDN).

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-bb62e564f2f2984012baab09b32bcd7a052135d0%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* After Purge Cache the files `/purge_lab/demo1.txt`... Were called back to Origin to get new content.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-5bd0cd8f1e8673724d6129d00296fde9bb9e87fc%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* Files `/purge_lab/text1.txt`... Still get content from Cache in CDN

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-519b987af9193ebc87f7ee9d2f22480441fc1e8a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### 4. Purge Cache By END. <a href="#id-4.-purge-cache-by-end" id="id-4.-purge-cache-by-end"></a>

Purge by END: Will delete all resources that are being cached in vCDN at the end of the input string.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-f3ea5a312ea4ee16bf383c357c0660e19d2b00d5%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* Similar to Purge by ALL, before Purge Cache, the files have been cached in CDN. Proceed to Purge Cache: Select **Service** and corresponding **CDN and Purge by END** . At URI enter: `/*1.txt` (clear cache of all \*1.txt files currently cached in CDN).

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-2e12508f3710f21f989717eba712356fb7638337%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* After Purge Cache the files `/*1.txt`... Were called back to Origin to get new content.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-b4d9038e28d37d6c076b457f1ea046140f322782%2Fimage%20(311).png?alt=media" alt=""><figcaption></figcaption></figure>

* Files `/purge_lab/text1.txt`... Still get content from Cache in CDN.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-1951884ec8d733b24df72ddbe1ae0a6d96df262d%2Fimage%20(312).png?alt=media" alt=""><figcaption></figcaption></figure>

### 5. Purge Cache By URI(s). <a href="#id-5.-purge-cache-by-uri-s" id="id-5.-purge-cache-by-uri-s"></a>

Purge by URI(s): Will delete exactly the specified link.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-d1a832e9b0102a9cad2518352ec93afb9d785b2d%2Fimage%20(313).png?alt=media" alt=""><figcaption></figcaption></figure>

* Similar to Purge by ALL, before Purge Cache, the files have been cached in CDN. Proceed to Purge Cache: Select **Service** and corresponding **CDN and Purge by URI(s)** . At URI, enter: `/purge_lab/demo1.txt`, `/purge_lab/demo2.txt`... (clear cache of specified links that are cached in vCDN).

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-397ab0c17261abaedb9cc184e22d2b615c8d189c%2Fimage%20(314).png?alt=media" alt=""><figcaption></figcaption></figure>

* After Purge Cache the files `/purge_lab/demo1.txt`... Were called back to Origin to get new content.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-d4b38440c1ab88ab3bdfd89ac7b1aa426a36637e%2Fimage%20(315).png?alt=media" alt=""><figcaption></figcaption></figure>

* Other files not specified Purge Cache ... Still fetch content from Cache in CDN.

<figure><img src="https://1985221522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7rE7M1L7GYcwQzNGd0aB%2Fuploads%2Fgit-blob-ab5bfd67a35de9b9429389fd01b5d70bac959160%2Fimage%20(316).png?alt=media" alt=""><figcaption></figcaption></figure>
