Over a million developers have joined DZone.

Windows Server AppFabric Cache - Custom Cache Provider Deployment

DZone's Guide to

Windows Server AppFabric Cache - Custom Cache Provider Deployment

Free Resource

Download the Altoros NoSQL Performance Benchmark 2018. Compare top NoSQL solutions – Couchbase Server v5.5, MongoDB v3.6, and DataStax Enterprise v6 (Cassandra).

1. Create CustomCache class that extends from Microsoft.ApplicationServer.Caching.DataCacheStoreProvider.

2. Override and Implement all the required methods.

3. Create a Strong Name key using:
sn.exe CustomCacheProvider.snk

4. Assign the strong named key to CustomCacheProvider assembly.

5. GAC CustomCacheProvider assembly using:
Gacutil.exe /i CustomCacheProvider

6. Capture the fully qualified name of this assembly that is deployed in the Global Assembly Cache using:
Gacutil.exe /l CustomCacheProvider

You will get the following details [For Example]

e:\APPS\Microsoft Visual Studio 10.0\VC>gacutil.exe /l CustomCacheProvider

Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.1

Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:

CustomCacheProvider, Version=, Culture=neutral, PublicKeyToken=b3fae62df3e2d49e

Number of items = 1

Note – The PublicKeyToken may vary based on your machine.

7. With the above details you would need only to append the qualified class name as shown below:

CustomCacheProvider.CustomCache, CustomCacheProvider, Version=, Culture=neutral, PublicKeyToken=b3fae62df3e2d49e

8. When you create a new Cache from Power Shell command window, you will have to use the above information to register this assembly for the Cache. For example:
New-Cache MyCustomCache -ReadThroughEnabled true -WriteBehindEnabled true -WriteBehindInterval 60 -ProviderType "CustomCacheProvider, Version=, Culture=neutral, PublicKeyToken=b3fae62df3e2d49e" -ProviderSettings @{"connString"=" DATABASE_CONNECTION_STRING";"Your_Custom_Key"="Your_Custom_Value"}
Note: The database connection string is for target database. This is to facilitate Custom Cache Provider to connect and fetch configurable items from target table under SQL Server database.

9. The above step will create an entry in the Windows Server AppFabric Cache configuration [which is ClusterConfig.xml file in the case of file configuration and table level in the case of SQL as storage]under the dataCache Section as shown below:

<cache consistency="StrongConsistency" name="SKCacheEx1" minSecondaries="0">


<eviction type="Lru" />

<expiration defaultTTL="10" isExpirable="true" />


<writeBehind enabled="true" interval="60" />

<readThrough enabled="true" />

<provider type="CustomCacheProvider.CustomCache, CustomCacheProvider, Version=, Culture=neutral, PublicKeyToken=b3fae62df3e2d49e">


<add key="ConnectionString" value=" DATABASE_CONNECTION_STRING" />






10. Make sure the key - " DATABASE_CONNECTION_STRING" is maintained the same in the code while you retrieve connection string values from the CacheProvider class constructor.

11. Deploy this assembly in to each cache host in the cache cluster.

Download the whitepaper, Moving From Relational to NoSQL: How to Get Started. We’ll take you step by step through your first NoSQL project.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}