How to clear cache when closing the Report Viewer
To clear the server-side cache of the Bold Reports® Angular 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.
TypeScript
Add the following code to the index.html file to clear the Report Viewer cache and destroy the viewer before the page unloads.
<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>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;
}