Today, we will address one of the most frequently asked questions by our users: how to enable report caching from code?

Typical mistake

The ReportCacheMode property is responsible for report caching, which users often enable before loading the report. For example:
StiReport report = new StiReport();
report.ReportCacheMode = StiReportCacheMode.On;
report.Load(path);
In this scenario, report caching will not be enabled, and here is why: The required ReportCacheMode property, like most report properties, is saved in the report template. Therefore, any value set before loading the report will be overwritten by the value from the template.

Solution

To enable report caching from code, you need to set the ReportCacheMode property to On not before, but AFTER loading the report.

Accordingly, the code will look like this:
StiReport report = new StiReport();
report.Load(path);
report.ReportCacheMode = StiReportCacheMode.On;

Technical intricacies

Another frequently asked question: Why is the ReportCacheMode property not saved in the template, yet it is still set to Off after loading the report?

To reduce the size of the template file, only those properties whose values differ from the default value are written to it during saving. Before loading the template using the report.Load() method, most properties are automatically set to their default values. During the loading process, properties are then set to the values from the template.

Therefore, if a property is changed before the report is loaded, it will still be set to its default value before the report is loaded.
By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.