How do I disable App Cache for Azure App Service?

Lunde, Gaute 0 Reputation points
2023-05-05T08:12:16.76+00:00

I have a Linux-based docker application running in Azure App Service. The docker image spins up an apache server, which serves html files from a mounted Azure Blob Storage container.

This works fine until the content in the mounted blob container is updated. All pages have a date to show when they were created. When visiting a page that has been visited before, the content is not updated. However, visiting a never before viewed page yields the new version. This leads me to believe this is a caching issue. Furthermore, the App Service application runs on an app service plan with two instances. When repeatedly refreshing a page that has been visited once, the date displayed alternates between the new and old date. This means the cache is per instance, not shared.

I have SSH'ed into the instance and verified that the content in the mounted blob storage container does not match what is in blob storage.

So my question is, how do I turn off this caching, or make sure it is invalidated? If I stop the app and start it again, all content is updated, but I cannot stop and start it every time a new version is uploaded. I have tried the following configuration settings, to no avail:

WEBSITE_DYNAMIC_CACHE=0
WEBSITE_LOCAL_CACHE_OPTION=Disabled (and Never)
WEBSITES_ENABLE_APP_CACHE=false

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,931 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Denis Kathuri 0 Reputation points Student Ambassador
    2023-05-05T08:41:48.2933333+00:00

    Sign in to the Azure portal and navigate to your App Service.

    Click on "Configuration" from the left-hand menu.

    Scroll down to the "General settings" section and toggle the "Web Sockets" option to "Off".

    Scroll down to the "Application settings" section and click on "Add new setting".

    Set the "Key" to "SCM_USE_MAIN_HUB_ENDPOINT" and the "Value" to "1".

    Click on "Save" to apply the changes.

    These steps will disable App Cache for your Azure App Service. Note that App Cache is not recommended for production environments as it can cause issues with caching stale data. If you need to use caching in your application, consider using a more robust caching solution such as Azure Redis Cache or Azure Cosmos DB.

    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-05-08T15:34:12.03+00:00

    when apache serves the page, it sets the expiration header (browser cache). the browser then caches the page. You need to disable this via apache configuration:

    https://www.howtogeek.com/devops/how-to-configure-cache-control-headers-in-apache/

    you may want to use apaches etag support. which set the cache header based on file attributes.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.