# 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](https://www.telerik.com/products/reporting/documentation/embedding-reports/html5-viewer-telerik-rest-service) and [REST Service Storage Settings](https://www.telerik.com/products/reporting/documentation/embedding-reports/host-the-report-engine-remotely/rest-service-storage/overview).

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.

```C#

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

```VB.NET

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
```

```C#

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();
    }
}
```

```VB.NET

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](https://learn.microsoft.com/en-us/dotnet/api/system.type.assemblyqualifiedname?view=net-7.0#System_Type_AssemblyQualifiedName) of MyCacheProvider type. The following code snippet demonstrates how to configure such custom provider:

```XML
<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

* [Configuring Cache](https://www.telerik.com/products/reporting/documentation/embedding-reports/cache-management/configuring-cache)
* [Configuring the File Cache Provider](https://www.telerik.com/products/reporting/documentation/embedding-reports/cache-management/configuring-the-file-cache-provider)
* [Configuring the Database Cache Provider](https://www.telerik.com/products/reporting/documentation/embedding-reports/cache-management/configuring-the-database-cache-provider)
