Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Tip
You can also ask Microsoft Copilot in Azure these questions:
To find Copilot in Azure, on the Azure portal toolbar, select Copilot.
Azure App Service content is stored in Azure Storage and is exposed as a durable content share. This design works with various apps and has the following attributes:
Although many apps use one or more of these features, some apps need a high-performance, read-only content store that they can run from with high availability. Such apps can benefit from running against a local cache on the VM instance.
The local cache feature in Azure App Service provides a web role view of your content. This content is a write-but-discard cache of your storage content that's created asynchronously at site startup. When the cache is ready, the site switches to run against the cached content.
Apps running with a local cache benefit in these ways:
Note
The local cache feature isn't supported in function apps or containerized App Service apps, such as in Windows containers or in App Service on Linux. A version of the feature that's available for these app types is App Cache.
The local cache feature also isn't supported in the F1 and D1 pricing tiers of App Service.
Configuring a local cache causes these changes:
D:\home
now points to the local cache, which is created on the VM instance when the app starts. D:\local
continues to point to the temporary, VM-specific storage.
The local cache contains a one-time copy of the /site
and /siteextensions
folders from the shared content store. These folders are located at D:\home\site
and D:\home\siteextensions
, respectively. These files are copied to the local cache at app startup.
The size of these two folders is limited to 1 GB by default, but you can increase it to 2 GB. As the cache size increases, it takes longer to load the cache. If you increase the local cache limit to 2 GB and the copied files exceed this maximum size, App Service silently ignores the local cache and reads from the remote file share.
Important
When the copied files exceed the defined size limit for the local cache, or when no limit is defined, deployment and swap operations might fail with an error. For details, see the FAQ about size limits later in this article.
The local cache is read/write. However, any modifications are discarded when the app moves between VMs or restarts. Don't use the local cache for storing mission-critical data.
D:\home\LogFiles
and D:\home\Data
contain log files and app data. These folders are stored locally on the VM instance and are periodically copied to the shared content store. Although apps can persist log files and data by writing to these folders, the copy process is best-effort. Log files and data might be lost if a VM instance suddenly stops responding.
The best-effort copy affects log streaming. You might observe up to a one-minute delay in streamed logs.
In the shared content store, the folder structure for LogFiles
and Data
changes for apps that use a local cache. There are now subfolders with names that consist of a unique identifier and a time stamp. Each subfolder corresponds to a VM instance where the app is or was running.
Other folders in D:\home
remain in the local cache and aren't copied to the shared content store.
App deployments via any supported method publish directly to the durable shared content store. To refresh the D:\home\site
and D:\home\siteextensions
folders in the local cache, you must restart the app. For a seamless life cycle, see the section about best practices later in this article.
The default content view of the SCM site continues to reflect the shared content store.
Note
If you're using Java (Java SE, Tomcat, or JBoss EAP), then by default, the Java artifacts (.jar, .war, and .ear files) are copied locally to the worker. If your Java application depends on read-only access to additional files, set JAVA_COPY_ALL
to true
so that those files are also copied. If a local cache is enabled, it takes precedence over this Java-specific behavior.
You configure a local cache by using a combination of reserved app settings. You can set these app settings by using one of the following methods.
Enable a local cache on a per-web-app basis by adding this app setting:
WEBSITE_LOCAL_CACHE_OPTION
= Always
.
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "appsettings",
"dependsOn": [
"[resourceId('Microsoft.Web/sites/', variables('siteName'))]"
],
"properties": {
"WEBSITE_LOCAL_CACHE_OPTION": "Always",
"WEBSITE_LOCAL_CACHE_SIZEINMB": "1000"
}
}
By default, the local cache size is 1 GB. This size includes the /site
and /siteextensions
folders copied from the content store. It also includes any locally generated logs and data folders.
To increase this limit, use the app setting WEBSITE_LOCAL_CACHE_SIZEINMB
. You can increase the size up to 2 GB (2,000 MB) per app. Keep in mind that a larger cache size increases the time to load the cache.
We recommend using a local cache in conjunction with the staging environments feature.
The following process represents the best practices for using a local cache:
Add the sticky app setting WEBSITE_LOCAL_CACHE_OPTION
with the value Always
to your production slot. If you're using WEBSITE_LOCAL_CACHE_SIZEINMB
, also mark that setting as a sticky setting for the production slot.
Create a staging slot and publish to it. Typically, you don't set the staging slot to use a local cache, which helps enable a seamless build/deploy/test life cycle while still providing local cache benefits for the production slot.
Test your site in the staging slot.
When you're ready, perform a swap operation between the staging and production slots.
Sticky settings are tied to the slot. When the staging slot is swapped into production, it inherits the local cache's app settings. The newly swapped production slot runs against the local cache after a few minutes and is warmed up during slot warmup. After the swap is complete, your production slot runs against the local cache.
If the copied files exceed the size limit for the local cache, the app reverts to reading from the remote share. The following table shows the details.
Local cache size | Copied files | Result |
---|---|---|
≤ 2 GB | ≤ local cache size | Reads from the local cache. |
≤ 2 GB | > local cache size | Reads from the remote share. Deployment and swap operations might fail with an error. |
A local cache is a good fit if all these conditions apply:
To check the total size of your /site
and /siteextensions
folders, you can use the site extension Azure Web Apps Disk Usage.
When you're using a local cache with staging environments, the swap operation doesn't finish until the local cache is warmed up. To verify that your site is running against the local cache, check the worker process environment variable WEBSITE_LOCALCACHE_READY
. To inspect this variable across multiple instances, refer to the Kudu instructions for the worker process environment variable.
If your app uses a local cache, you must restart the site to load the latest changes. If you prefer not to publish changes directly to your production site, consider using deployment slots as described in the earlier section about best practices.
Note
The run from package deployment option isn't compatible with the local cache feature.
When you're using a local cache, the structure of your log and data folders changes slightly. The subfolders are now nested under a folder that's named with the unique VM identifier and a time stamp. Each of these folders corresponds to the VM instance where the app is or was running.
A local cache helps prevent storage-related app restarts. However, your app might still restart during planned infrastructure upgrades on the VM. Overall, you should observe fewer restarts with a local cache enabled.
During the copy process, any folder named repository
is excluded. This behavior is useful in scenarios where your site content includes a source control repository that you don't need for day-to-day operations.
To flush the local cache logs, stop and restart the app. This action clears the previous cache.
If previously deployed files reappear after a restart, check for the presence of the app setting WEBSITE_DISABLE_SCM_SEPARATION=true
. Adding this setting causes deployments via Kudu to write to the local VM instead of persistent storage. To avoid this situation, follow the best practices mentioned earlier and perform deployments to a staging slot that doesn't have a local cache enabled.
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today