0
0
Azurecloud~5 mins

Why caching improves performance in Azure - Why It Works

Choose your learning style9 modes available
Introduction
Caching stores copies of data in a fast storage area so that future requests for that data can be served quickly. This reduces the time it takes to get data and lowers the load on the main data source.
When your web app needs to show the same data to many users quickly without asking the database every time
When you want to reduce the cost and delay of repeatedly fetching data from a slow or expensive service
When you want to improve user experience by making pages or features load faster
When you want to handle more users at once without slowing down your system
When you want to avoid repeated calculations by storing results temporarily
Config File - azure-cache-config.json
azure-cache-config.json
{
  "name": "myCache",
  "location": "eastus",
  "sku": {
    "name": "Standard",
    "family": "C",
    "capacity": 1
  },
  "enableNonSslPort": false,
  "redisConfiguration": {
    "maxmemory-policy": "allkeys-lru"
  }
}

This JSON configures an Azure Cache for Redis instance named myCache in the East US region.

The sku section sets the cache size and type.

enableNonSslPort is false to enforce secure connections.

The redisConfiguration sets the eviction policy to remove least recently used keys when memory is full.

Commands
This command creates an Azure Redis Cache instance named 'myCache' in the 'eastus' region under the resource group 'myResourceGroup'. It uses the Standard SKU with a small VM size and disables the non-SSL port for security.
Terminal
az redis create --name myCache --resource-group myResourceGroup --location eastus --sku Standard --vm-size C1 --enable-non-ssl-port false
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Cache/Redis/myCache", "location": "eastus", "name": "myCache", "properties": { "provisioningState": "Succeeded", "hostName": "myCache.redis.cache.windows.net", "port": 6379, "sslPort": 6380 }, "sku": { "name": "Standard", "family": "C", "capacity": 1 }, "type": "Microsoft.Cache/Redis" }
--sku - Sets the cache type and size
--enable-non-ssl-port - Disables insecure connections
This command retrieves details about the Redis Cache instance to verify it was created successfully and check its settings.
Terminal
az redis show --name myCache --resource-group myResourceGroup
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Cache/Redis/myCache", "location": "eastus", "name": "myCache", "properties": { "provisioningState": "Succeeded", "hostName": "myCache.redis.cache.windows.net", "port": 6379, "sslPort": 6380 }, "sku": { "name": "Standard", "family": "C", "capacity": 1 }, "type": "Microsoft.Cache/Redis" }
This command sets a maintenance window on Monday at 2 AM for 60 minutes to apply updates without unexpected downtime.
Terminal
az redis patch-schedule create --name myCache --resource-group myResourceGroup --day-of-week Monday --start-hour 2 --maintenance-window 60
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Cache/Redis/myCache/patchSchedules/Default", "dayOfWeek": "Monday", "startHourUtc": 2, "maintenanceWindow": 60 }
--day-of-week - Specifies the day for maintenance
--start-hour - Specifies the hour to start maintenance
Key Concept

If you remember nothing else from this pattern, remember: caching stores data closer to where it is needed to make access much faster and reduce load on slower sources.

Common Mistakes
Not disabling the non-SSL port when creating the cache
This allows insecure connections that can expose data to attackers
Always set --enable-non-ssl-port false to enforce secure connections
Not verifying the cache creation with az redis show
You might think the cache is ready when it is still provisioning or failed
Run az redis show to confirm the cache is provisioned and ready
Not setting a maintenance window
Updates can happen at unexpected times causing downtime
Use az redis patch-schedule create to set a predictable maintenance time
Summary
Create an Azure Redis Cache instance with secure settings using az redis create.
Verify the cache is ready with az redis show before using it.
Set a maintenance window to control when updates happen and avoid surprises.