Invalidating CDN Cache With a Custom Rule
Start course

This course provides an overview of Redis Cache and how to create a Redis Cache instance in Azure. With Redis Cache deployed in Azure, we’ll then connect an application to the cache.
Next, we’ll walk through the process of storing and retrieving data in Redis Cache. After covering Redis Cache, we’ll walk through an overview of what CDN is and what it’s used for. We’ll then develop some code for leveraging CDN. As we wrap up the course, we’ll cover the process for invalidating data in both Redis Cache and in a CDN.

Intended Audience

This course is intended for IT professionals who are interested in earning Azure certification and those who need to incorporate Redis Cache or CDN into their solutions. To get the most from this course, you should have at least a moderate understanding of what caching is and why it’s used.

Learning Objectives

By the end of this course, you should have a good understanding of what Redis Cache and CDN are and what purposes they serve. You’ll also know how to connect to each from applications and how to purge or invalidate data in both.


- While we're in here looking at caching rules for our CDN cache, let's take a look at a custom caching rule. What we're going to do in this demonstration is define a custom caching rule that invalidates our CDN cache after a specified amount of time. What we're going to do in this demonstration is use a custom caching rule to set a cache duration of one second on our cdndemo.htm file. What this will do is override any cache control or expires http headers that are sent by the originating server. 

So to create our custom caching rule, we'll browse down here, down to the custom caching rule section. So to define our custom caching rule, we'll go down to the bottom here where it says custom caching rules. So to create our custom caching rule, what we're going to do is go down to the bottom here where it says custom caching rules. What we're going to do for the match condition field is set it to path. The value we're going to match on is our cdndemo.htm file. The caching behavior we're going to set is override and we're going to tell it that we want a cache duration of one second. We can go ahead and save our new rule. 

With our new rule in place, what we'll do is go up to our web app and we'll refresh it. And we can see we have black text. If we switch over to our end point, we can refresh and we see we have black text. Now what I'm going to do is go into my FTP client again and I'm going to edit the text color back to red. Now if I go back up to my application and refresh, we can see I get red text. Now what I would expect in my end point is that a refresh also displays red text. This is because the custom rule down here should override the default cache expiration of seven days because I'm focused on the cdndemo.htm match. So let's go up here and do a refresh and as you can see here, the text is in fact red. So what this demonstrates is that I can control individual caching with custom caching rules. Our custom rule here that matches on the cdndemo.htm file overrides the default caching expiration duration of seven days. And if you read closely under the custom caching rule section, Microsoft will tell you that these rules override the default settings above and that they're evaluated from top to bottom. That being said, rules that are lower in this list can override rules that are further above it. So keep that in mind when you start creating custom caching rules.

About the Author
Learning Paths

Tom is a 25+ year veteran of the IT industry, having worked in environments as large as 40k seats and as small as 50 seats. Throughout the course of a long an interesting career, he has built an in-depth skillset that spans numerous IT disciplines. Tom has designed and architected small, large, and global IT solutions.

In addition to the Cloud Platform and Infrastructure MCSE certification, Tom also carries several other Microsoft certifications. His ability to see things from a strategic perspective allows Tom to architect solutions that closely align with business needs.

In his spare time, Tom enjoys camping, fishing, and playing poker.