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

Find out how Database DevOps helps your team deliver value quicker while keeping your data safe and your organization compliant. Align DevOps for your applications with DevOps for your SQL Server databases to discover the advantages of true Database DevOps, brought to you in partnership with Redgate

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.

Align DevOps for your applications with DevOps for your SQL Server databases to increase speed of delivery and keep data safe. Discover true Database DevOps, brought to you in partnership with Redgate

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}