Articles in this section
Category / Section

How to Clear Cache in the Bold Reports Designer Application

Published:
Updated:

When using the Report Designer in Bold Reports, temporary data is stored in the designer cache during the report design process. To ensure this cached data is automatically removed when the Report Designer is closed, you can bind a cache-clearance method to the beforeunload event.

This implementation ensures that cached data is cleared whenever the user closes the Report Designer tab, helping maintain optimal performance and storage efficiency.

ReportDesignerController.cs

An API is defined in the controller to handle cache deletion. It checks whether the cache directory exists and deletes it if found.

[HttpGet]
public void DisposeDesignerCache(string key)
{
   string targetFolder = this._hostingEnvironment.WebRootPath + "/";
   targetFolder += "Cache";

   if (Directory.Exists(targetFolder + "/" + key))
   {
       Directory.Delete(targetFolder + "/" + key, true);
   }
} 

DesignerReport.cshtml

In the front-end code, the disposeDesignerCache function is bound to the beforeunload event to ensure that the designer cache is cleared when the Report Designer tab is closed.

var isFormSubmit = true;
var controlId = "designer";

window.addEventListener('beforeunload', function (event) {
   disposeDesignerCache();
   isFormSubmit = true;
});

function disposeDesignerCache() {
   var designer = $('#' + controlId).data('boldReportDesigner');
   var designerToken = designer.authenticationToken;

   $.ajax({
       url: '/api/ReportDesigner/DisposeDesignerCache?key=' + designerToken, // Adjust the URL based on your controller's route
       type: 'GET',
       success: function (response) {
           console.log("Cache cleared:", response);
       },
       error: function (xhr, status, error) {
           console.error("Error clearing cache:", error);
       }
   });
} 

Click here to download the ASP.NET Core Designer Sample for reference.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied