|
| 1 | +--- |
| 2 | +title: Tutorial - Control Azure CDN caching behavior with caching rules | Microsoft Docs |
| 3 | +description: In this tutorial, you set a global and a custom CDN caching rule. |
| 4 | +services: cdn |
| 5 | +documentationcenter: '' |
| 6 | +author: dksimpson |
| 7 | +manager: akucer |
| 8 | +editor: '' |
| 9 | + |
| 10 | +ms.service: cdn |
| 11 | +ms.workload: tbd |
| 12 | +ms.tgt_pltfrm: na |
| 13 | +ms.devlang: na |
| 14 | +ms.topic: tutorial |
| 15 | +ms.date: 04/19/2018 |
| 16 | +ms.author: v-deasim |
| 17 | +ms.custom: mvc |
| 18 | +# As an Azure CDN administrator, I want to create custom rules on my CDN endpoint so that I can control how content is cached. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +# Tutorial: Control Azure CDN caching behavior with caching rules |
| 23 | + |
| 24 | +> [!NOTE] |
| 25 | +> Caching rules are available only for **Azure CDN Standard from Verizon** and **Azure CDN Standard from Akamai**. For **Azure CDN Premium from Verizon**, use the [Azure CDN rules engine](cdn-rules-engine.md) in the **Manage** portal for similar functionality. |
| 26 | + |
| 27 | +Azure Content Delivery Network (CDN) offers two ways to control how your files are cached: |
| 28 | + |
| 29 | +- Caching rules: This article describes how you can use content delivery network (CDN) caching rules to set or modify default cache expiration behavior both globally and with custom conditions, such as a URL path and file extension. Azure CDN provides two types of caching rules: |
| 30 | + - Global caching rules: You can set one global caching rule for each endpoint in your profile, which affects all requests to the endpoint. The global caching rule overrides any HTTP cache-directive headers, if set. |
| 31 | + - Custom caching rules: You can set one or more custom caching rules for each endpoint in your profile. Custom caching rules match specific paths and file extensions, are processed in order, and override the global caching rule, if set. |
| 32 | + |
| 33 | +- Query string caching: You can adjust how the Azure CDN treats caching for requests with query strings. For information, see [Control Azure CDN caching behavior with query strings](cdn-query-string.md). If the file is not cacheable, the query string caching setting has no effect, based on caching rules and CDN default behaviors. |
| 34 | + |
| 35 | +For information about default caching behavior and caching directive headers, see [How caching works](cdn-how-caching-works.md). |
| 36 | + |
| 37 | +In this tutorial, you learn how to: |
| 38 | +> [!div class="checklist"] |
| 39 | +> - Open the caching rules page |
| 40 | +> - Create a global caching rule |
| 41 | +> - Create a custom caching rule |
| 42 | +
|
| 43 | +[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)] |
| 44 | + |
| 45 | +## Prerequisites |
| 46 | + |
| 47 | +Before you can complete the steps in this tutorial, you must first create a CDN profile and at least one CDN endpoint. For more information, see [Quickstart: Create an Azure CDN profile and endpoint](cdn-create-new-endpoint.md). |
| 48 | + |
| 49 | +## Open the Azure CDN caching rules page |
| 50 | + |
| 51 | +1. In the [Azure portal](https://portal.azure.com), select a CDN profile, then select an endpoint. |
| 52 | + |
| 53 | +2. In the left pane under Settings, select **Caching rules**. |
| 54 | + |
| 55 | +  |
| 56 | + |
| 57 | + The caching rules page appears. |
| 58 | + |
| 59 | +  |
| 60 | + |
| 61 | + |
| 62 | +## Set global caching rules |
| 63 | + |
| 64 | +Create a global caching rule as follows: |
| 65 | + |
| 66 | +1. Under **Global caching rules**, set **Query string caching behavior** to **Ignore query strings**. |
| 67 | + |
| 68 | +2. Set **Caching behavior** to **Set if missing**. |
| 69 | + |
| 70 | +3. For **Cache expiration duration**, enter 10 in the **Days** field. |
| 71 | + |
| 72 | + The global caching rule affects all requests to the endpoint. This rule honors the origin cache-directive headers, if they exist (`Cache-Control` or `Expires`); otherwise, if they are not specified, it sets the cache to 10 days. |
| 73 | + |
| 74 | +  |
| 75 | + |
| 76 | +## Set custom caching rules |
| 77 | + |
| 78 | +Create a custom caching rule as follows: |
| 79 | + |
| 80 | +1. Under **Custom caching rules**, set **Match condition** to **Path** and **Match value** to `/images/*.jpg`. |
| 81 | + |
| 82 | +2. Set **Caching behavior** to **Override** and enter 30 in the **Days** field. |
| 83 | + |
| 84 | + This custom caching rule sets a cache duration of 30 days on any `.jpg` image files in the `/images` folder of your endpoint. It overrides any `Cache-Control` or `Expires` HTTP headers that are sent by the origin server. |
| 85 | + |
| 86 | +  |
| 87 | + |
| 88 | + |
| 89 | +## Clean up resources |
| 90 | + |
| 91 | +In the preceding steps, you created caching rules. If you no longer want to use these caching rules, you can remove them by performing these steps: |
| 92 | + |
| 93 | +1. Select a CDN profile, then select the endpoint with the caching rules you want to remove. |
| 94 | + |
| 95 | +2. In the left pane under Settings, select **Caching rules**. |
| 96 | + |
| 97 | +3. Under **Global caching rules**, set **Caching behavior** to **Not set**. |
| 98 | + |
| 99 | +4. Under **Custom caching rules**, select the check box next to the rule you want to delete. |
| 100 | + |
| 101 | +5. Select **Delete**. |
| 102 | + |
| 103 | +6. From the top of the page, select **Save**. |
| 104 | + |
| 105 | + |
| 106 | +## Next steps |
| 107 | + |
| 108 | +What you learned: |
| 109 | + |
| 110 | +> [!div class="checklist"] |
| 111 | +> - Opened the caching rules page |
| 112 | +> - Created a global caching rule |
| 113 | +> - Created a custom caching rule |
| 114 | +
|
| 115 | +Advance to the next tutorial to learn how to configure additional caching rule settings. |
| 116 | + |
| 117 | +> [!div class="nextstepaction"] |
| 118 | +> [Control Azure CDN caching behavior with caching rules](cdn-caching rules.md) |
| 119 | +
|
| 120 | + |
| 121 | + |
0 commit comments