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
For more information, review the following help topics:
- Use .NET CLI Template to Create an ASP.NET Core Reporting Application with Report Designer
- Use Visual Studio Templates to Create an ASP.NET Core Application with a Report Designer
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
Log into your Microsoft account from Visual Studio.
In Solution Explorer, right-click the project name and click Publish.
Select Azure and click Next.
Select the Azure App Service (Linux) and click Next.
On the App Service tab, click Create new.
If necessary, change the Name, Resource group, or Hosting Plan values, and click Create.
Select the newly created service and click Finish.
After the publishing profile is successfully created, scroll down to the Service Dependencies section, click the Storage ellipsis button, and select Connect:
In the Connect to dependency dialog select one of the available Azure Storage accounts (if any) or click Create New:
If necessary, change the Name, Resource group, or Hosting Plan values, and click Create.
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.
The configuration procedure adds code to your application. Rebuild the application and fix any problems.
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:
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: