Skip to main content
All docs
V24.1

How to Implement an Azure Storage Cache

  • 3 minutes to read

Overview

The Document Viewer and Report Designer preview mode require access to the document during its generation. A report and document cache is used to organize temporary information storage between requests to avoid excessive document generation operations.

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

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

Cache Management API

The following code configures the application to use caching for document generation:

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

Create a Reporting Application with Azure Storage Cache

Use Visual Studio or .NET command-line templates to create an ASP.NET Reporting sample application. Specify Azure as the storage type to cache documents that the report creates.

dotnet new dx.reporting --name <application name> --DocumentStorage Azure

Specify Azure Storage Type

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 setting in the appsettings.json file is set to UseDevelopmentStorage=true, which enables you to run the application on the local host and use Azurite emulator and Azure Storage Explorer to debug and test the application locally.

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, click the Storage ellipsis button, and select Connect:

    Storage Dependencies Connect

  9. In the Connect to dependency dialog select one of the available Azure Storage accounts (if any) or click Create New:

    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. You can choose to leave them unchanged 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.

You can 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: