New to Telerik Reporting? Download free 30-day trial

Configuring Custom Cache Providers

The cache settings mentioned in this article are not obligatory, and they do not apply to the HTML5 Report Viewer or its Angular, WebForms, MVC and other wrappers. Details about the Cache Storage of the Reporting REST Service that works with the HTML5 Report Viewer are available in Report Viewer and Reporting REST services and REST Service Storage Settings.

Except the preconfigured cache providers, additional providers can be used. To do that create a MyCache class that implements the Telerik.Reporting.Cache.Interfaces.ICache interface. Then implement the Telerik.Reporting.Cache.Interfaces.ICacheProvider interface and its only method should return a new instance of the MyCache class.

The cache provider should have a parameterless constructor in order to be instantiated by the Reporting engine.

public class MyCacheProvider : Telerik.Reporting.Cache.Interfaces.ICacheProvider
{
    public Cache.Interfaces.ICache CreateCache(System.Collections.IDictionary parameters)
    {
        return new MyCache(parameters);
    }
}
Public Class MyCacheProvider
    Implements Telerik.Reporting.Cache.Interfaces.ICacheProvider

    Public Function CreateCache(parameters As IDictionary) As Telerik.Reporting.Cache.Interfaces.ICache Implements ICacheProvider.CreateCache
        Return New MyCache(parameters)
    End Function

End Class
public class MyCache : Telerik.Reporting.Cache.Interfaces.ICache
{
    readonly System.Collections.Generic.IDictionary<string, byte[]> cache;

    public MyCache(System.Collections.IDictionary parameters)
    {
        // The 'parameters' dictionary is initialized from the Telerik.Reporting/Cache configuration section.

        this.cache = new System.Collections.Generic.Dictionary<string, byte[]>();
    }

    public bool HasValue(string key)
    {
        return this.cache.ContainsKey(key);
    }

    public byte[] GetValue(string key)
    {
        return this.cache[key];
    }

    public void SetValue(string key, byte[] value)
    {
        this.cache[key] = value;
    }

    public void Clear()
    {
        this.cache.Clear();
    }

    public void Dispose()
    {
        this.Clear();
    }
}
Public Class MyCache
    Implements Telerik.Reporting.Cache.Interfaces.ICache

    ReadOnly cache As System.Collections.Generic.Dictionary(Of String, Byte())

    Public Sub New(parameters As System.Collections.IDictionary)

        ' The 'parameters' dictionary is initialized from the Telerik.Reporting/Cache configuration section.

        Me.cache = New System.Collections.Generic.Dictionary(Of String, Byte())()
    End Sub

    Public Function HasValue(key As String) As Boolean Implements ICache.HasValue
        Return Me.cache.ContainsKey(key)
    End Function

    Public Function GetValue(key As String) As Byte() Implements ICache.GetValue
        Return Me.cache(key)
    End Function

    Public Sub SetValue(key As String, value As Byte()) Implements ICache.SetValue
        Me.cache(key) = value
    End Sub

    Public Sub Clear() Implements ICache.Clear
        Me.cache.Clear()
    End Sub

    Public Sub Dispose() Implements IDisposable.Dispose
        Me.Clear()
    End Sub
End Class

To register this new provider set the provider attribute of the "Cache" element to the class name which implements ICacheProvider. Under "Providers" child element of the "Cache" element, create a "Provider" element with the same name attribute as the provider attribute of the "Cache" element. The type attribute should be the assembly qualified name of MyCacheProvider type. The following code snippet demonstrates how to configure such custom provider:

<Telerik.Reporting>
    <Cache provider="MyCacheProvider">
        <Providers>
            <Provider name="MyCacheProvider" type="MyNameSpace.MyCacheProvider, AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
                <Parameters>
                    <Parameter />
                </Parameters>
            </Provider>
        </Providers>
    </Cache>
</Telerik.Reporting>

See Also

In this article