Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Windows Server AppFabric Cache - Custom Cache Provider Deployment

DZone's Guide to

Windows Server AppFabric Cache - Custom Cache Provider Deployment

Free Resource

Running out of memory? Learn how Redis Enterprise enables large dataset analysis with the highest throughput and lowest latency while reducing costs over 75%! 

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=1.0.0.0, 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=1.0.0.0, Culture=neutral, PublicKeyToken=b3fae62df3e2d49e
Note: It is NAMESPACENAME.CLASSNAME, ASSEMBLYNAME, Version...

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=1.0.0.0, 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">

<policy>

<eviction type="Lru" />

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

<backingStore>

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

<readThrough enabled="true" />

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

<settings>

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

</settings>

</provider>

</backingStore>

</policy>

</cache>

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.

Running out of memory? Never run out of memory with Redis Enterprise databaseStart your free trial today.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}