Skip to main content
All docs
V25.2
  • Implement an Azure Storage Cache

    • 4 minutes to read

    Overview

    The Document Viewer and Report Designer Preview require access to the document while it is being generated. Report and document caches store temporary data between requests and help avoid unnecessary document generation.

    For additional information on caching mechanisms and document creation, review the following help topics:

    This topic describes API objects and methods for caching and explains how to create and publish an ASP.NET Core application that uses Azure Storage for report and document caching.

    Configure an ASP.NET Core Application

    Use DevExpress Templates

    Use our Project Template Kit or .NET CLI Templates to create an ASP.NET Reporting application with required configuration. Specify AzureStorage as the storage type to cache documents that the report creates.

    dotnet new dx.aspnetcore.reporting --name <application name> --DocumentStorage AzureStorage
    

    For more information, review the following help topics:

    The created project already includes the DevExpress.AspNetCore.Reporting.Azure NuGet package and the UseAzureCachedReportSourceBuilder method call at startup.

    The Azure Storage connection string in the appsettings.json file sets the UseDevelopmentStorage setting to true. With this configuration, you can run the application on the local host and use Azurite emulator and Azure Storage Explorer to debug and test the application locally.

    Get an instance of IAzureResourceProvisionService from the ServiceCollection and call the CreateRequiredResourcesAsync() method to create and configure the required resources in Azure Storage data services and in the Service Bus:

    using DevExpress.XtraReports.Web.Azure;
    //...
    using(var serviceScope =  app.Services.CreateScope()) {
      var azureResourceInitializer = serviceScope.ServiceProvider.GetService<IAzureResourceProvisionService>();
      azureResourceInitializer.CreateRequiredResourcesAsync().GetAwaiter().GetResult();
    }
    

    Call the CreateRequiredResourcesAsync method only once to create and configure the required resources.

    Configure an Existing Application

    If you have an ASP.NET Core application with integrated Document Viewer or Report Designer, follow the steps below:

    1. Install the DevExpress.AspNetCore.Reporting.Azure NuGet package.

    2. Add the Azure Storage connection string to the appsettings.json file:

      {
        "ConnectionStrings": {
          "AzureStorageConnectionString": "UseDevelopmentStorage=true"
        }
      }
      
    3. Ensure that you use caching for document generation. To do this, call the UseCachedReportSourceBuilder method in the ConfigureReportingServices method:

      using DevExpress.AspNetCore.Reporting;
      using DevExpress.AspNetCore.Reporting.Azure;
      // ...
      var builder = WebApplication.CreateBuilder(args);
      // ...
      builder.Services.ConfigureReportingServices(configurator => {
          // ...
          configurator.ConfigureReportDesigner(designerConfigurator => {
          });
          configurator.ConfigureWebDocumentViewer(viewerConfigurator => {
              viewerConfigurator.UseCachedReportSourceBuilder();
              viewerConfigurator.UseAzureCachedReportSourceBuilder(builder.Configuration.GetConnectionString("AzureStorageConnectionString"), StorageSynchronizationMode.InterThread);
          });
      });
      //...
      

      The Azure Storage connection string is to match the name of the connection string in appsettings.json.

    4. Get an instance of IAzureResourceProvisionService from the ServiceCollection and call the CreateRequiredResourcesAsync() method to create and configure the required resources in Azure Storage data services and in the Service Bus:

      using DevExpress.XtraReports.Web.Azure;
      //...
      using(var serviceScope =  app.Services.CreateScope()) {
        var azureResourceInitializer = serviceScope.ServiceProvider.GetService<IAzureResourceProvisionService>();
        azureResourceInitializer.CreateRequiredResourcesAsync().GetAwaiter().GetResult();
      }
      

      Call the CreateRequiredResourcesAsync method only once to create and configure the required resources.

    Publish the Application

    1. Log into your Microsoft account from Visual Studio.

    2. In Solution Explorer, right-click the project name and click Publish.

    3. Select Azure and click Next.

      Select Publish to Azure

    4. Select the Azure App Service (Linux) and click Next.

      Select the Azure App Service (Linux)

    5. On the App Service tab, click Create new.

      App Service Create New

    6. If necessary, change the Name, Resource group, or Hosting Plan values, and click Create.

      Change the Name, Resource Group or Hosting Plan

    7. Select the newly created service and click Finish.

      Newly Created Azure App Service

    8. After the publishing profile is successfully created, scroll down to the Service Dependencies section and select Add a service dependency:

      Storage Dependencies Connect

    9. In the Add dependency dialog select Azure Storage and click Next.:

      Create New Storage Account

    10. If necessary, change the Name, Resource group, or Hosting Plan values, and click Create.

      Create New Azure Storage

    11. Once you select the Azure storage account, you are prompted to change the connection string settings. Ensure that the connection string name matches the name in appsettings.json and click Finish.

      Connect to Dependency and Modify Connection String

    12. The configuration procedure adds code to your application. Rebuild the application and fix any problems.

    13. Click Publish in the Publish window.

      Click Publish in the Publish Window

    Test the Published Application

    Once the publishing process is complete, click the Site link in the Publish window to open the application page.

    Use Azure Storage Explorer to connect to Azure Storage and view tables and blob containers:

    Azure Storage Explorer

    The Web Document Viewer stores service information in Table Storage and saves document files in Blob Storage.

    Note

    You can use a custom storage instead of Table and Blob storages. To do this, implement one of the following interfaces and substitute related services in a container:

    See Also