How to clear cache when closing the Report Viewer

To clear the server-side cache of the Bold Reports® JavaScript Report Viewer, call the clearReportCache and destroy methods. Use these methods when you close the Report Viewer or switch to another report in your application.

Javascript

<div id="reportviewer"></div>
<script>
 var isSubmit = true;
 $(document.body).bind('submit', $.proxy(this.formSubmit, this));
function formSubmit(args)
{
        isSubmit = false;
}

window.onbeforeunload = function () {
if (isSubmit) {
var reportviewerObj = $("#reportviewer").data("boldReportViewer");
        reportviewerObj.clearReportCache();
        reportviewerObj.destroy();
}

isSubmit = true;

};
</script>

How do I clear the report cache in the Report Viewer Web API?

In the Report Viewer Web API PostReportAction method, run the GC collection when the report action is ClearCache, as in the following code sample.

public object PostReportAction([FromBody] Dictionary<string, object> jsonArray)
{
  bool isclearcache = false;
  if (jsonArray != null && jsonArray.ContainsKey("reportAction") && jsonArray["reportAction"].ToString() == "ClearCache")
  {
    isclearcache = true;
  }
  var reportresult = ReportHelper.ProcessReport(jsonArray, this, this._cache);
  if (isclearcache)
  {
      GC.Collect(); isclearcache = false;
  }

 return reportresult;
}

See also