Integrate caching and content delivery within solutions

Last Updated on December 13, 2020 by

Integrate caching and content delivery within solutions is part of Monitor, troubleshoot, and optimize Azure solutions topics. the total weight of this in the exam will be 10-15%. This training post is designed to help and provide readers with a better understanding of the topic mentioned.

Disclaimer: This is not a training article to help complete the Microsoft Azure AZ-204, but it provides a good insight into the areas within these topics. Labs and hands-on work are essential to passing most Microsoft Azure exams.

Integrate caching and content delivery within solutions:
develop code to implement CDN’s in solutions

Integrate caching and content delivery within solutions:

Content delivery networks (CDNs)

A content delivery network (CDN) is a distributed network of servers that can efficiently deliver web content to users. CDNs store cached content on edge servers that are close to users to minimize latency. These Edge servers are located in point-of-presence (POP) locations that are distributed throughout the globe.

Improving the client experience by using a CDN

With traditional internet distribution, a single server sends content to each end user.

A CDN delivers content through a network of servers that are closer to end users.

  • Without a CDN, content delivery suffers, yielding a poor customer experience because of routing complications, traffic and congestion, the explosion of devices, network types, and richer, more sophisticated content.
  • Security threats start at the network layer, and attacks are increasing in scale and sophistication.
  • Many customers might feel that CDN isn’t worth the extra effort. They want to avoid multi-year contracts and added complexity.

CDN uses

Typical uses for a CDN include:

  • Delivering static resources, often from a website, for client applications. These resources can be images, style sheets, documents, files, client-side scripts, HTML pages, HTML fragments, or any other content that the server does not need to modify for each request.
  • Delivering public static and shared content to devices such as mobile phones and tablets.
  • Serving entire websites that consist of only public static content to clients without requiring any dedicated compute resources.
  • Streaming video files to client devices on demand, taking advantage of the low latency and reliable connectivity available from the globally located datacenters that offer CDN connections.
  • Supporting Internet of Things (IoT) solutions. The huge numbers of devices and appliances involved in an IoT solution can easily overwhelm an application if it has to distribute firmware updates directly to each device.
  • Coping with peaks and surges in demand without requiring the application to scale, avoiding the consequent increased running costs.
CDNs are typically used to deliver static content, such as images, style sheets, documents, client-side scripts, and HTML pages.

Create Azure CDN endpoints and domains by using Azure CLI

After you have created a new profile, you can use that profile to create an endpoint. Each endpoint requires you to specify a profile, a resource group, and an origin URL.
Integrate caching and content delivery within solutions:
configure cache and expiration policies for FrontDoor, CDNs, or Redis caches

Integrate caching and content delivery within solutions

Cache expiration in Azure CDN

Because a cached resource can potentially be out-of-date or stale (compared to the corresponding resource on the origin server), it is important for any caching mechanism to control when content is refreshed.

Caching rules

Azure CDN caching rules specify cache expiration behavior both globally and with custom conditions. There are two types of caching rules:

Global caching rules. You can set one global caching rule for each endpoint in your profile that affects all requests to the endpoint. The global caching rule overrides any HTTP cache-directive headers if set.

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.

Purging and preloading assets by using Azure CLI

The Azure CLI provides a special purge verb that will unpublish cached assets from an endpoint. This is very useful if you have an application scenario where a large amount of data is invalidated and should be updated in the cache. To unpublish assets, you must specify either a file path, a wildcard directory, or both.

Integrate caching and content delivery within solutions:
store and retrieve data in Azure Redis cache

Integrate caching and content delivery within solutions


Redis is typically used as a cache to improve the performance and scalability of systems that rely heavily on backend data stores. Performance is improved by temporarily copying frequently accessed data to fast storage located close to the application.

Data in Redis is stored in nodes and clusters.

Nodes are a space in Redis where your data is stored.

Clusters are sets of three or more nodes your dataset is split across. Clusters are useful because your operations will continue if a node fails or is unable to communicate to the rest of the cluster.

Redis data types

Redis supports a variety of data types, all oriented around binary safe strings. This means that you can use any binary sequence for a value, from a string like “i-love-rocky-road” to the contents of an image file. An empty string is also a valid value.

Here’s a list of the most common data types:

  • Binary-safe strings (most common)
  • Lists of strings
  • Unordered sets of strings
  • Hashes
  • Sorted sets of strings
  • Maps of strings

Example key schema

application:last_updated_stringJanuary 01, 2016

Redis keys are also binary safe strings. Here are some guidelines for choosing keys:

Avoid long keys

They take up more memory and require longer lookup times because they have to be compared byte-by-byte. If you want to use a binary blob as the key, generate a unique hash and use that as the key instead. The maximum size of a key is 512 MB, but you should never use a key that size.

Use keys that can identify the data

For example, “sport:football;date:2008-02-02” would be a better key than “fb:8-2-2”. The former is more readable and the extra size is negligible. Find the balance between size and readability.

Use a convention

A good one is “object:id”, as in “sport:football”

Azure Cache for Redis

Azure Cache for Redis is based on the popular software Redis. With Azure Cache for Redis, the fast storage commonly associated with Redis is located in-memory with Azure Cache for Redis instead of being loaded from disk by a database.

Application performance is improved by taking advantage of the low-latency, high-throughput performance of the Redis engine.

Azure Cache for Redis gives you access to a secure, dedicated Azure Cache for Redis, managed by Microsoft, hosted within Azure, and accessible to any application within or outside of Azure.

Azure Cache for Redis usage

Azure Cache for Redis can also be used as an in-memory data structure store, a distributed non-relational database, and a message broker.

Because a database can be large, loading an entire database into a cache is not a recommended approach. It is common to use the cache-aside pattern to load data items into the cache only as needed. When the system makes changes to the back-end data, it can at that time also update the cache, which is distributed with other clients. Additionally, the system can set an expiration on data items, or use an eviction policy to cause data updates to be reloaded into the cache.

More topics on Monitor, troubleshoot, and optimize Azure solutions:

Instrument solutions to support monitoring and logging

Microsoft Azure AZ-204 exam topics:

If you have covered the current topics in Monitor, troubleshoot, and optimize Azure solutions then you can have a look at the other topic areas:

View full documentation Microsoft Azure: AZ-204 exam content from Microsoft

2 Responses to “Integrate caching and content delivery within solutions”

  • You actually make it seem so easy together with your presentation however I
    find this topic to be actually one thing which I think I would by no
    means understand. It sort of feels too complicated and extremely huge for me.
    I’m having a look forward to your subsequent put up,
    I’ll attempt to get the grasp of it!

  • I’m no longer certain where you are getting your info, but great topic.
    I must spend some time finding out much more or working out more.
    Thank you for fantastic info I used to be in search of this info for my mission.

Leave a Reply

Your email address will not be published. Required fields are marked *