Search results
Suggest a FeaturePDF

File Storage for Memory in Report Viewer

Overview

Report Viewer uses a file storage feature to manage data that might otherwise be held in memory, thus enhancing scalability in report processing and rendering operations. This is particularly beneficial in environments with limited RAM or when handling large volumes of data.

ASP.NET Core Platform

The following code example demonstrates how to enable cache file storage in the Report Viewer.

Steps to Enable File Storage:

  1. Inherit Interface: Inherit the IReportHelperSettings interface in your Report viewer controller. Shows the configuration of Inherit the IReportHelperSettings

  2. Implement Interface Methods: Provide implementations for the required interface methods as shown below. Shows the configuration of Inherit the IReportHelperSettings

  3. Initialize File Storage Settings:

    helperSettings.StorageSettings = new CacheStorageSettings();
    helperSettings.StorageSettings.Provider = StorageProvider.File;
    helperSettings.StorageSettings.ItemTypes = StorageItemTypes.Report;

    Shows the configuration of Inherit the IReportHelperSettings

  4. Add CacheStorageSettings Class:

    public class CacheStorageSettings : BoldReports.Web.StorageSettings
    {
        public override byte[] GetBytes(string key, string storageModelType)
        {
            try
            {
                var fileDirectory = Path.Combine("Need to provide the report rendering cache file storage directory", key, key + "-" + storageModelType + ".json");
                if (File.Exists(fileDirectory))
                {
                    return File.ReadAllBytes(fileDirectory);
                }
            }
            catch (Exception ex)
            {
                // Log your error.
            }
            return null;
        }
    
        public override void SetBytes(string key, byte[] value, string storageModelType)
        {
            try
            {
                string fileDirectory = Path.Combine("Need to provide the report rendering cache file storage directory", key);
                if (!Directory.Exists(fileDirectory))
                {
                    Directory.CreateDirectory(fileDirectory);
                }
                var jsonFile = Path.Combine(fileDirectory, key + "-" + storageModelType + ".json");
                File.WriteAllBytes(jsonFile, value);
            }
            catch (Exception ex)
            {
                // Log your error.
            }
        }
    
        public override void Delete(string key)
        {
            try
            {
                string fileDirectory = Path.Combine("Need to provide the report rendering cache file storage directory", key);
                if (Directory.Exists(fileDirectory))
                {
                    Directory.Delete(fileDirectory, true);
                }
            }
            catch (Exception ex)
            {
                // Log your error.
            }
        }
    }