azureazure-web-app-servicekudu

Azure kudu files with local cache enabled getting deleted automatically


We have a page developed and deployed to Azure app service with local cache enabled.

Through code we are creating a file and writing data to it in Azure Kudu /home/site/wwwroot/*** folders* . When we run the page, file is getting created and deleted instantly. when we browse file, it got created with required data and if I reload i m getting file not found error.

Could you please suggest a solution , how to persist this file inside kudu (any path) and keep updating based on requirement ?

Note: Same solutions working in dev environment. Only difference for prod is Local cache

Tried to provide /home, /home/local , /data folders but same issue. Since its successfully getting created, no error is shown to debug


Solution

  • When we run the page, file is getting created and deleted instantly. when we browse file, it got created with required data and if I reload i m getting file not found error.

    string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
    string filePath = Path.Combine(appDataFolder, "yourfile.txt");
    
    
    // use the /tmp directory.
    
    string filePath = Path.Combine(Path.GetTempPath(), "your_file_name.txt");
    File.WriteAllText(filePath, "your_data");
    

    Using the Environment.GetFolderPath method you can get the App Data folder path.

    You can also try writing the file to a different directory outside of the /home directory. Use the /tmp directory as shown in above code snippet it used for temporary files and should not be affected by the local cache.

    If local cache causing issues and you don't need it for your application, then disabling it. By this no local caching is performed, and your files will be directly written to and read from the file system.

    enter image description here