The Angular Viewer component allows you to use the server cache to store rendered reports. If you do not use caching, then, every time you request a page, you should load the report, connect data, and render it again. If you use caching, every time you refresh the page, the previously rendered report will be loaded from the cache.

 

When using caching, it should be taken into account that every report saved in the cache takes up server memory and, with a large number of requests to reports, this can become a critical issue. Therefore, you need to choose between two options - either low memory requirements but high in performance, or low performance requirements but high in memory.

 

To use caching, you need to connect modules to work with a session or cache on the server side. To do this, just add the following services to the project in the start file of a project.

 

Startup.cs

...

public void ConfigureServices(IServiceCollection services)

{

services.AddMemoryCache();

services.AddSession();

services.AddMvc();

}

...

 

 

You can manage caching with the following properties.

 

The CacheMode property

 

This property of the viewer enabled caching and sets its type. It can take one of the following values, specified in the StiServerCacheMode enumeration:

 

None – caching is disabled, each action of the viewer requires loading the report from the file and, if it is a report template, then render it;

ObjectCache – for caching, the server cache is used. The report object is saved in this cach (set by default);

StringCache – for caching, the server cache is used. The report is saved as a packed string in this cache;

ObjectSession – the current session, in which the report object is saved, is used for caching;

StringSession – for caching, the current session is used. The report is saved as a packed string in this cache.

 

 

The CacheItemPriority property

 

This property sets the priority of the report stored in the server's cache. It affects the automatic clearing of the server memory in case of lack of memory. The lower the priority is, the greater is the chance of removing information from memory.

 

 

The CacheTimeout property

 

This property specifies the amount of time in minutes for which you want to save the report in the server cache. If you use caching and the requested report is not found in the cache (the objects storage time has expired), then it will be requested again using a special GetReport event, then connect the report data and render it.

 

 

StiCacheHelper

 

The Angular Viewer component provides the ability to define your own methods of working with report caching. For this purpose, a special class StiCacheHelper is used. It contains methods for obtaining a report from the cache and saving the report to the cache. It is necessary to create a new class inherited from StiCacheHelper and reload the above methods, which respectively have the names - GetReport and SaveReport.

 

HomeController.cs

...

public class ViewerController : Controller

{

public class StiMyCacheHelper : StiCacheHelper

{

public override StiReport GetReport(string guid)

{

string path = System.IO.Path.Combine(this.HttpContext.Server.MapPath("CacheFiles"), guid);

if (System.IO.File.Exists(path))

{

StiReport report = new StiReport();

string packedReport = System.IO.File.ReadAllText(path);

if (guid.EndsWith("template")) report.LoadPackedReportFromString(packedReport);

else report.LoadPackedDocumentFromString(packedReport);

 

return report;

}

return null;

 

//return base.GetReport(guid);

}

 

public override void SaveReport(StiReport report, string guid)

{

string packedReport = guid.EndsWith("template") ? report.SavePackedReportToString() : report.SavePackedDocumentToString();

string path = System.IO.Path.Combine(this.HttpContext.Server.MapPath("CacheFiles"), guid);

System.IO.File.WriteAllText(path, packedReport);

 

//base.SaveReport(report, guid);

}

}

 

static ViewerController()

{

StiAngularViewer.CacheHelper = new StiMyCacheHelper();

}

}

...

 

 

To initialize the work with report caching using the created class, it is enough to set it as a value of the static StiAngularViewer.CacheHelper property in the controller constructor.

 

Information

 

If report caching is disabled (the CacheMode property of the viewer is set to None), the specified class will not be used.