How to clear cache when closing the Report Viewer
By using the clearReportCache and destroy method, you can clear the server side cache. You have to use this method when closing report viewer and switching to another report within your application.
JavaScript
Add the following code in index.js file.
class Header extends React.Component {
constructor(props) {
}
componentDidMount() {
$(document.body).bind('submit', $.proxy(window.addEventListener, window));
}
}
var isSubmit = true;
$(document.body).bind('submit', $.proxy(window.addEventListener, window));
function addEventListener()
{
isSubmit = false;
}
window.onbeforeunload = function () {
if (isSubmit) {
var reportviewerObj = $("#reportviewer-container").data("boldReportViewer");
reportviewerObj.clearReportCache();
reportviewerObj.destroy();
}
isSubmit = true;
};
ReactDOM.render(<App {...isSubmit} />, document.getElementById('root'));Web API
In the PostReportAction method, you have to collect the GC with ClearCache as shown 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;
}