Over a million developers have joined DZone.

Windows Server AppFabric Cache Programming

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

Named Cache

The named cache in AppFabric cache through AppFabric Cache Administration console, using the following Powershell command:

New-Cache myCache

New-Cache myCache -ReadThroughEnabled true -ProviderType "CustomCacheProvider, Version=, Culture=neutral, PublicKeyToken=b3fae62df3e2d49e" -ProviderSettings @{"CacheName"="myCache";} –TimeToLive 1440

Regions in Cache

Each named Cache can contain one or more named regions. Regions are an additional data container used to isolate and hold data in the cache. All items in each region stored together Default region created for each Cache if none explicitly created. You must create a region programmatically before trying to store an item inside them. Once you start using Regions you must always reference the region by their names.

var dcf = new DataCacheFactory();

//get the cache named "myCache"

var cache = dcf.GetCache("myCache");

//Add a region named "region1" - returns false //if already exists

var ret = cache.CreateRegion("region1", false);

Usage patterns

The AppFabric cache maintains its data in physical memory. It is not guaranteed that these data remain forever in cache and hence cannot assume that cache client's to run smoothly. There may be a case where, we would come across the whole cache cluster going down. In these situations, the cache client should be armed with intelligent mechanisms to make calls to external data storage respository and continue to support application availability.

There are multiple ways and strategies available to handle such kind of scenarios. We have 1) Cache-aside programming model and 2) Read-through / write-behind programming model. In the Cache-aside programming model, it is the responsibility of the cache-client to explicitly make calls to SQL Server (external storage repository) to fetch results, store them inside cache and consume. In this case, additional SQL connection is made to query and handle data un-availability in cache. In the Read-through / write-behind programming model, we create custom cache provider assembly, that makes explicit calls to SQL Server database and stores items in cache when one is un-available during request. In this case, the cache client is reduced with burden of making extra calls to database. Plus, when items are written to a cache, the written items are periodically and asynchronously written to the backend.

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}