<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>jagan_peri</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/jagan_peri/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/jagan_peri/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:50:14 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Using Enterprise Transient fault handling block with Azure Cache</title>
      <link>https://docs.microsoft.com/archive/blogs/jagan_peri/using-enterprise-transient-fault-handling-block-with-azure-cache</link>
      <pubDate>Tue, 06 Nov 2012 08:31:00 GMT</pubDate>
      <dc:creator><![CDATA[Jagan Peri - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jagan_peri/2012/11/06/using-enterprise-transient-fault-handling-block-with-azure-cache/</guid>
      <description><![CDATA[&nbsp;I mentioned in an earlier blog about the importance of having a retry mechanism in...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;<span style="font-size: small;">I mentioned in an earlier <a title="blog" href="https://blogs.msdn.com/b/jagan_peri/archive/2012/09/09/best-practices-for-using-windows-azure-cache-windows-server-appfabric-cache.aspx">blog</a> about the importance of having a retry mechanism in applications that use Azure Cache. An easy way to do this is by using the <a title="enterprise transient fault handling block" href="https://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx">enterprise transient fault handling block</a>.</span></p>
<p><span style="font-size: small;">I've noticed that an application using the Windows Azure SDK 1.8 (October 2012 release) and Transient Fault handling block (version 5.1.1209.0) can fail to start with the callstack below:</span></p>
<pre class="scroll"><code class="csharp">System.Reflection.TargetInvocationException occurred<br /> HResult=-2146232828<br /> Message=Exception has been thrown by the target of an invocation.<br /> Source=mscorlib<br /> StackTrace:<br /> at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck)<br /> at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)<br /> at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)<br /> at System.Activator.CreateInstance[T]()<br /> at Microsoft.Practices.TransientFaultHandling.RetryPolicy`1..ctor(RetryStrategy retryStrategy)<br /> at WebRole1._Default.Page_Load(Object sender, EventArgs e) in c:\Projects\WindowsAzure1\WebRole1\Default.aspx.cs:line 23<br /> InnerException: System.IO.FileLoadException<br /> HResult=-2146234304<br /> Message=Could not load file or assembly 'Microsoft.ApplicationServer.Caching.Core, Version=101.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)<br /> Source=mscorlib<br /> FileName=Microsoft.ApplicationServer.Caching.Core, Version=101.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35<br /> FusionLog==== Pre-bind state information ===</code></pre>
<p>&nbsp;</p>
<p><span style="font-size: small;">Here is a simple workaround to get past this issue - In your application config (app.config or web.config), add the following assembly redirection snippet:</span></p>
<p>&nbsp;</p>
<pre class="scroll"><code class="csharp">&lt;configuration&gt;<br /> &lt;runtime&gt;<br /> &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;<br /> &lt;dependentAssembly&gt;<br /> &lt;assemblyIdentity name="Microsoft.ApplicationServer.Caching.Core"<br /> publicKeyToken="31bf3856ad364e35"<br /> culture="neutral" /&gt;<br /> &lt;!-- Assembly versions can be redirected in application, <br /> publisher policy, or machine configuration files. --&gt;<br /> &lt;bindingRedirect oldVersion="101.0.0.0" newVersion="1.0.0.0" /&gt;<br /> &lt;/dependentAssembly&gt;<br /> &lt;/assemblyBinding&gt;<br /> &lt;/runtime&gt;<br /> &lt;/configuration&gt;<br /></code> </pre>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>AppFabric 1.1 is now supported on Windows Server 2012</title>
      <link>https://docs.microsoft.com/archive/blogs/jagan_peri/appfabric-1-1-is-now-supported-on-windows-server-2012</link>
      <pubDate>Tue, 06 Nov 2012 08:08:00 GMT</pubDate>
      <dc:creator><![CDATA[Jagan Peri - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jagan_peri/2012/11/06/appfabric-1-1-is-now-supported-on-windows-server-2012/</guid>
      <description><![CDATA[&nbsp;
AppFabric 1.1 is now supported on Windows Server 2012. The download page has been updated to...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>AppFabric 1.1 is now supported on Windows Server 2012. The<a title="download page" href="https://www.microsoft.com/en-us/download/details.aspx?id=27115"> download page</a> has been updated to reflect this.</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Best Practices for using Windows Azure Cache/Windows Server Appfabric Cache</title>
      <link>https://docs.microsoft.com/archive/blogs/jagan_peri/best-practices-for-using-windows-azure-cachewindows-server-appfabric-cache</link>
      <pubDate>Sun, 09 Sep 2012 00:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Jagan Peri - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jagan_peri/2012/09/09/best-practices-for-using-windows-azure-cachewindows-server-appfabric-cache/</guid>
      <description><![CDATA[We frequently get asked on best practices for using Windows Azure Cache/Appfabric cache.&nbsp; The...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: medium;">We frequently get asked on best practices for using Windows Azure Cache/Appfabric cache.&nbsp; The compilation below is an attempt at putting together an initial list of best </span><span style="font-size: medium;">practices. I&rsquo;ll publish an update to this in the future if needed.</span></p>
<p><span style="font-size: medium;">I&rsquo;m breaking down the best practices to follow by various topics.</span></p>
<h1>Using Cache APIs</h1>
<h2>1.&nbsp;&nbsp;&nbsp;&nbsp;Have Retry wrappers around cache API calls</h2>
<p><span style="font-size: medium;">Calls into cache client can occasionally fail due to a number of reasons such as transient network errors, cache&nbsp; servers being unavailable due to maintainance/upgrades or cache servers being low on memory. The cache client raises a DataCacheException with an errorcode that indicates the reason for the failure in these cases. There is a good overview of how an application should handle these exceptions in <a href="https://msdn.microsoft.com/en-us/library/ff637716">MSDN</a></span></p>
<p><span style="font-size: medium;">It is a good practice for the application to implement a retry policy. You can implement a custom policy or consider using a framework like the <a href="https://msdn.microsoft.com/library/hh680901(v=PandP.50).aspx">TransientFault Handling Application Block</a></span></p>
<h2>2.&nbsp;&nbsp;&nbsp;&nbsp;Keep static instances of DataCache/DataCacheFactory</h2>
<p><span style="font-size: medium;">Instances of DataCacheFactory (and hence DataCache instances indirectly) maintain tcp connections to the cache servers. These objects are expensive to create and destroy. In addition, you want to have as few of these as needed to ensure cache servers are not overwhelmed with too many connections from clients</span>.</p>
<p><span style="font-size: medium;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/65/0246.dcf.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-65/0246.dcf.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/65/0246.dcf.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-65/0246.dcf.png" border="0" /></a></span></p>
<p><span style="font-size: medium;">You can find more details of connection management <a href="https://msdn.microsoft.com/en-us/library/windowsazure/hh552970.aspx">here</a>. Please note that the ability to share connections across factories is currently available only in November 2011 release of the Windows Azure SDK (and higher versions). Windows Server appfabric 1.1 does not have this capability yet. </span></p>
<p><span style="font-size: medium;">Overhead of creating new factory instances is lower if connection pooling is enabled. In general though, it is a good practice to pre-create an instance of DataCacheFactory/DataCache and use them for all subsequent calls to the APIs. Do avoid creating an instance of DataCacheFactory/DataCache on </span><span style="font-size: medium;">each of your request processing paths.&nbsp;</span></p>
<h2>3.&nbsp;&nbsp;&nbsp;&nbsp;WCF Services using Cache Client</h2>
<p><span style="font-size: medium;">It is a common practice for WCF services to use cache to improve their performance. However, unlike asp.net web applications, wcf services are susceptible for IO-thread starvation issues when making blocking calls (such as cache API calls) that further require IO threads to receive responses (such as responses from cache servers).</span></p>
<p><span style="font-size: medium;">This issue is described in detail in the following <a href="https://support.microsoft.com/kb/2538826">KB article</a>&nbsp;&ndash; The typical symptom that surfaces if you run into this is that when you&rsquo;ve a sudden burst of load, cache API calls timeout. You can confirm if you are</span><br /><span style="font-size: medium;">running into this situation by plotting the thread count values against incoming requests/second as shown in the KB article.</span></p>
<h2>4.&nbsp;&nbsp;&nbsp;&nbsp;If app is using Lock APIs - Handle ObjectLocked, ObjectNotLocked exceptions</h2>
<p><span style="font-size: medium;">If you are using lock related APIs, please ensure you are handling exceptions such as <a href="https://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacacheerrorcode.objectlocked(v=ws.10).aspx">ObjectLocked</a>&nbsp;( and <a href="https://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacacheerrorcode.objectnotlocked(v=ws.10)">ObjectNotLocked</a>&nbsp;(Object being referred to is not locked by any client) error.</span></p>
<p><span style="font-size: medium;">GetAndLock can fail with <i>&ldquo;&lt;</i><i>ERRCA0011&gt;:</i><i>SubStatus&lt;ES0001&gt;:</i><i>Object being referred to is currently locked, and cannot be accessed until it is unlocked by the locking client. Please retry later.&rdquo;</i> error if another caller has acquired a lock on the object.</span></p>
<p><span style="font-size: medium;">The code should handle this error and implement an appropriate retry policy.</span></p>
<p><span style="font-size: medium;">PutAndUnlock can fail with &ldquo;&lt;ERRCA0012&gt;:SubStatus&lt;ES0001&gt;:Object being referred to is not locked by any client&rdquo; error.</span></p>
<p><span style="font-size: medium;">This typically means that the lock timeout specified when the lock was acquired was not long enough because the application request took longer to process. Hence the lock expired before the call to PutAndUnlock and the cache server returns this error code.</span></p>
<p><span style="font-size: medium;">The typical fix here is to both review your request processing time as well as set a higher lock timeout when acquiring a lock.</span></p>
<p><span style="font-size: medium;">You can also run into this error when using the session state provider for cache. If you are running into this error from session state provider, the typical solution is to set a higher executionTimeout for your web app.</span></p>
<h1>Session State Provider Usage</h1>
<p><span style="font-size: medium;">You can find more info about asp.net session state providers for appfabric cache <a href="https://msdn.microsoft.com/en-us/library/hh361700">here</a> and azure cache <a href="https://msdn.microsoft.com/en-us/library/windowsazure/gg185682">here</a>.</span></p>
<p><span style="font-size: medium;">The session state provider has an option to store the entire session as 1 blob (useBlobMode=&rdquo;true&rdquo; which is the default), or to store the session as individual key/value pairs.</span></p>
<p><span style="font-size: medium;">useBlobMode="true" incurs fewer round trips to cache servers and works well for most applications.</span></p>
<p><span style="font-size: medium;">If you've a mix of small and large objects in session, useBlobMode=&rdquo;false&rdquo; (a.ka. granular mode) might work better since it will avoid fetching the entire (large) session object for all requests. The cache should also be marked as nonEvictable cache if useBlobMode=&rdquo;false&rdquo; option is being used. Because Azure shared cache does not give you the ability to mark a cache as non evictable, please note that useBlobMode=&rdquo;true&rdquo; is the only supported option against Windows Azure Shared cache.</span></p>
<h1>Performance Tuning and Monitoring</h1>
<p>&nbsp;</p>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tune MaxConnectionsToServer</h2>
<p><span style="font-size: medium;">Connection management between cache clients and servers is described in more detail <a href="https://msdn.microsoft.com/en-us/library/windowsazure/hh552970.aspx">here</a>. Consider tuning <a href="https://msdn.microsoft.com/en-us/library/ee790816(v=azure.10).aspx">MaxConnectionToServer</a>&nbsp;setting. This setting controls the number of connections from a client to cache</span><br /><span style="font-size: medium;">servers. (MaxConnectionsToServer * Number of DataCacheFactory Instances *Number of Application Processes) is a rough value for the number of connections that will be opened to each of the cache servers. So, if you have 2 instances of your web role with 1 cache factory and MaxConnectionsToServer set to 3, there will be 3*1*2 = 6 connections opened to each of the cache servers.</span></p>
<p><span style="font-size: medium;">Setting this to number of cores (of the application machine) is a good place to start. If you set this too high, a large number of connections can get opened to each of the cache servers and can impact throughput.</span></p>
<p><span style="font-size: medium;">If you are using Azure cache SDK 1.7, maxConnectionsToServer is set to the default of number of cores (of the application machine). The on-premise appfabric cache (v1.0/v1.1) had the default as one, so that value might need to be tuned if needed</span>.</p>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Adjust Security Settings</h2>
<p><span style="font-size: medium;">The default <a href="https://msdn.microsoft.com/en-us/library/hh334328.aspx">security settings</a>&nbsp;for on-premise appfabric cache is to run with security on at EncryptAndSign protection level. If you are running in a trusted environment and don&rsquo;t need this capability, you can turn this off by explicitly setting security to off.</span></p>
<p><span style="font-size: medium;">The security model for Azure cache is different and theabove adjustment is not needed for azure cache.</span></p>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Monitoring</h2>
<p><span style="font-size: medium;">There is also a good set of performance counters on the cache servers that you can monitor to get a better understanding of cache performance issues. Some of the <a href="https://msdn.microsoft.com/en-us/library/ff637725(v=azure.10).aspx">counters</a>&nbsp;that are typically useful to troubleshoot issues include:</span></p>
<p><span style="font-size: medium;">1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%cpu used up by cache service</span></p>
<p><span style="font-size: medium;">2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%time spent in GC by cache service</span></p>
<p><span style="font-size: medium;">3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total cache misses/sec &ndash; A high value here can indicate your application performance might suffer because it is not able to fetch data from cache. Possible causes for this include eviction and/or expiry</span><br /><span style="font-size: medium;">of items from cache.</span></p>
<p><span style="font-size: medium;">4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total object count &ndash; Gives an idea of how many items are in the cache. A big drop in object count could mean eviction or expiry is taking place.</span></p>
<p><span style="font-size: medium;">5)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total client reqs/sec &ndash; This counter is useful in giving an idea of how much load is being generated on the cache servers from the application. A low value here usually means some sort of a bottleneck</span><br /><span style="font-size: medium;">outside of the cache server (perhaps in the application or network) and hence very little load is being placed on cache servers.</span></p>
<p><span style="font-size: medium;">6)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total Evicted Objects &ndash; If cache servers are constantly evicting items to make room for newer objects in cache, it is usually a good indication that you will need more memory on the cache servers to hold</span><br /><span style="font-size: medium;">the dataset for your application.</span></p>
<p><span style="font-size: medium;">7)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total failure exceptions/sec and Total Retry exceptions/sec</span></p>
<p>&nbsp;</p>
<h1>&nbsp;Lead host vs Offloading</h1>
<p><span style="font-size: medium;">This applies only for the on-premise appfabric cache deployments. There is a good discussion of the&nbsp; tradeoffs/options in this <a href="https://blogs.msdn.com/b/appfabric/archive/2011/07/06/lead-hosts-versus-sql-server-for-windows-server-appfabric-caching.aspx">blog</a>&nbsp;- As noted in the <a href="https://blogs.msdn.com/b/appfabric/archive/2011/07/06/lead-hosts-versus-sql-server-for-windows-server-appfabric-caching.aspx">blog</a>, with v1.1, you can use sql to just store config info and use lead-host model for cluster runtime. This option is attractive if setting up a highly-available sql server for offloading purposes is hard.</span></p>
<h1>Other Links</h1>
<p><span style="font-size: medium;">Here are a set of blogs/articles that provide more info on some of the topics covered above.</span></p>
<p><span style="font-size: medium;">1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jason Roth and Jaime Alva have written an &nbsp;<a href="https://msdn.microsoft.com/en-us/library/windowsazure/hh916611.aspx">article</a> providing additional guidance to developers using Windows</span><br /><span style="font-size: medium;">Azure Caching.</span></p>
<p><span style="font-size: medium;">2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jaime Alva&rsquo;s <a href="https://blogs.msdn.com/b/appfabriccat/archive/2010/12/14/logging-in-app-fabric-cache.aspx">blog</a>&nbsp;post on logging/counters for On-premise appfabric cache.</span></p>
<p><span style="font-size: medium;">3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MSDN <a href="https://msdn.microsoft.com/en-us/library/windowsazure/hh552970.aspx">article</a>&nbsp;about connection management between cache client &amp; servers.</span></p>
<p><span style="font-size: medium;">4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Amit Yadav and Kalyan Chakravarthy&rsquo;s <a href="https://blogs.msdn.com/b/appfabric/archive/2011/07/06/lead-hosts-versus-sql-server-for-windows-server-appfabric-caching.aspx">blog</a>&nbsp;on lead host vs offloading options for cache clusters.</span></p>
<p><span style="font-size: medium;">5)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MSDN <a href="https://msdn.microsoft.com/en-us/library/ff637716">article</a> on common cache exceptions and <a href="https://msdn.microsoft.com/library/hh680901(v=PandP.50).aspx">Transient Fault Handling Application Block</a></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Custom Serialization</title>
      <link>https://docs.microsoft.com/archive/blogs/jagan_peri/custom-serialization</link>
      <pubDate>Wed, 22 Aug 2012 23:42:00 GMT</pubDate>
      <dc:creator><![CDATA[Jagan Peri - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jagan_peri/2012/08/22/custom-serialization/</guid>
      <description><![CDATA[Azure Cache (Preview) release added support for using a custom serializer to serialize objects that...]]></description>
      <content:encoded><![CDATA[<p>Azure Cache (Preview) release added support for using a custom serializer to serialize objects that are stored in the cache.</p>
<div class="WordSection1">
<p class="MsoNormal">NetDataContractSerializer is the default serialization mechanism used b<a name="_GoBack"></a>y Azure cache. Many times, applications might need to use custom serialization for performance or compatibility reasons.</p>
<p class="MsoNormal">&nbsp;An application could explicitly serialize objects and store them in cache as byte[]'s. However, this&nbsp; results in sub-optimal performance when local cache is used since the cost of deserialization will be incurred even when retrieving items from local cache. Using the custom serializer support, access to objects in local cache does not incur any deserialization costs (on-par with default serialization approach).</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="font-size: 16pt; background-color: #ffffff;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-size: auto; background-origin: padding-box; background-clip: border-box;">Let's walk through a code example</span></span></p>
<p class="MsoNormal">&nbsp;</p>
<p>Instead of the default NetDataContractSerializer, we will create a custom serializer that uses Json serialization to serialize instances of&nbsp;Person class.&nbsp;&nbsp;Since we will use DataContractJsonSerializer for this example, we need to attribute this class as a DataContract.</p>
<p>&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; [</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataContract</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">]</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; {</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> Person(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> firstName, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> lastName)</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">this</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">.FirstName = firstName;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">this</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">.LastName = lastName;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataMember</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">]</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> FirstName { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">; }</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataMember</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">]</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> LastName { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">; }</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; }</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size: 16pt; background-color: #ffffff;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-size: auto; background-origin: padding-box; background-clip: border-box;">Implement the IDataCacheObjectSerializer interface</span></span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">Custom serializers need to implement the IDataCacheObjectSerializer interface - It has 2 methods (one each for Serialize and Deserialize).&nbsp; For this example, we will keep the implementation simple and use the System.Runtime.Serialization.Json.DataContractJsonSerializer class to do the actual work.</p>
<p class="MsoNormal">&nbsp;<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> WorkerRole1</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt;">/*</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp; * Simple implementation of IDataCacheObjectSerializer</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp; * Uses DataContractJsonSerializer</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp; */</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CustomSerializer</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">: </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IDataCacheObjectSerializer</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; {</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> CustomSerializer()</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { }</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">object</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> Deserialize(System.IO.</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Stream</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> stream)</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Trace</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">.WriteLine(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt;">"CustomSerializer.Deserialize method called"</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">); </span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataContractJsonSerializer</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> serializer = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataContractJsonSerializer</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">typeof</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">(</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">));</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> serializer.ReadObject(stream);</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">void</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> Serialize(System.IO.</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Stream</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> stream, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">object</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> value)</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Trace</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">.WriteLine(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt;">"CustomSerializer.Serialize method called"</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">);</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataContractJsonSerializer</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> serializer = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataContractJsonSerializer</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">typeof</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">(</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">));</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; serializer.WriteObject(stream, value);</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; }</span></p>
<p class="MsoNormal"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">}</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="font-size: 16pt; background-color: #ffffff;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-size: auto; background-origin: padding-box; background-clip: border-box;">Configure Cache Client to use the Custom Serializer</span></span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">This can be done either through xml configuration or through code.</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">Through XML Configuration:&nbsp;</p>
<p class="MsoNormal">Add the &lt;serializationProperties /&gt; element specifying serializer="CustomSerializer" and setting customSerializerType to the type that implements the custom serialization. In this case, WorkerRole1.CustomSerializer is the name of the class located in WorkerRole1.dll</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp; &lt;dataCacheClients&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; &lt;tracing sinkType="DiagnosticSink" traceLevel="Verbose" /&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; &lt;!-- This is the default config which is used for all Named Caches</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp; This can be overriden by specifying other dataCacheClient sections with name being the NamedCache name --&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; &lt;dataCacheClient name="default" useLegacyProtocol="false"&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;autoDiscover isEnabled="true" identifier="WorkerRole1" /&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!--&lt;localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" /&gt;--&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background: yellow;">&lt;serializationProperties serializer="CustomSerializer" customSerializerType="WorkerRole1.CustomSerializer,WorkerRole1" /&gt;</span></span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; &lt;/dataCacheClient&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp; &lt;/dataCacheClients&gt;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">You can also configure the custom serialization properties through code as shown below:</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCacheSerializationProperties</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> customSerializerProps = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCacheSerializationProperties</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">(</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCacheObjectSerializerType</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">.CustomSerializer,</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CustomSerializer</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">());</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCacheFactoryConfiguration</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> config = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCacheFactoryConfiguration</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt;">"default"</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">);</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt;">// Specify CustomSerialization Properties.</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: yellow; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.SerializationProperties = customSerializerProps;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCacheFactory</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> factory = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCacheFactory</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">(config);</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0pt;"><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DataCache</span><span style="background: white; color: black; font-family: Consolas; font-size: 9.5pt;"> cache = factory.GetDefaultCache();</span></p>
<h1>&nbsp;</h1>
<p class="MsoNormal"><span style="background: #ffffff; font-size: 16pt;">Testing the custom serializer</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;When you try out the code below that adds instances of type Person to cache, you can verify that the CustomSerializer class methods are being called.</span></p>
<p class="MsoNormal" style="margin-right: 6pt; margin-left: 6pt;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">Person p = new Person("Jagan", "Peri");<br /> cache.Put("key1", p);<br /> Person p2 = (Person)cache.Get("key1");<br /> <br /> </span></p>
<p class="MsoNormal"><span style="background: #ffffff; font-size: 16pt;">Limitations</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">1) As you can see from the above code snippets, there can be only one custom serializer specified at a DataCacheFactory level. If your application stores multiple types in the cache, the custom serializer needs to handle all these types.</p>
<p class="MsoNormal">2) Some APIs (increment, decrement, Append, Prepend) are not supported with custom serialization. These APIs require the cache server to understand the value stored in the cache<br />so it can perform these operations atomically on the value. Since custom serializer &nbsp;is only available on the client, these APIs cannot be used with custom serialization.</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="font-size: 16pt; background-color: #ffffff;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-size: auto; background-origin: padding-box; background-clip: border-box;">Sample Project</span></span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">&nbsp;I've attached a sample worker role that uses co-located cache and demonstrates the use of the above interface.</p>
<p class="MsoNormal">Key files to look at in this project are:</p>
<p class="MsoNormal">Person.cs - Type that is stored in cache</p>
<p class="MsoNormal">CustomSerializer.cs - Custom Serializer implementation</p>
<p class="MsoNormal">WorkerRole.cs - Configures CustomSerialization and performs cache put/get API calls.</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal"><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal">&nbsp;</p>
</div>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/34/26/20/CustomSerializer.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-34-26-20/CustomSerializer.zip">CustomSerializer.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Azure Cache (Preview)</title>
      <link>https://docs.microsoft.com/archive/blogs/jagan_peri/azure-cache-preview</link>
      <pubDate>Tue, 21 Aug 2012 10:51:00 GMT</pubDate>
      <dc:creator><![CDATA[Jagan Peri - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jagan_peri/2012/08/21/azure-cache-preview/</guid>
      <description><![CDATA[As a member on the Azure cache team, I was very thrilled when we released the Azure Cache (Preview)...]]></description>
      <content:encoded><![CDATA[<p>As a member on the Azure cache team, I was very thrilled when we released the Azure Cache (Preview) as part of the June 2012 Azure SDK.</p>
<p>&nbsp;</p>
<p>The preview offers a great caching solution for applications running on Azure. It provides a lot of benefits over Azure shared cache around aspects such as pricing, quotas/throttling and flexible deployment options.&nbsp;</p>
<p>In addition to the above areas of improvement over Azure shared cache, we also added a lot of other enhancements as part of the preview release.&nbsp; I've included an overview of these enhancements below.</p>
<p><strong></strong>&nbsp;</p>
<p><strong>New APIs</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The preview release contains the following new APIs:</p>
<p>&nbsp;</p>
<ol>
<li value="1"><a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj160033">DataCache()</a> - You don&rsquo;t need to use DataCacheFactory any more to create an instance of DataCache.</li>
<li><a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj160107">Increment</a> <a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj159979">Decrement</a> APIs - Many applications use cache to maintain numeric counters. These APIs are pretty useful for operating on numeric types stored in cache.</li>
<li><a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj160145">Append</a> <a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj160114">Prepend</a> APIs - Append or Prepend to a string that is stored in cache.</li>
<li><a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj160035">Cache level BulkGet</a> - This API supports bulk get of items from a cache. The earlier version of the API only allowed bulk get of items in a named region.</li>
<li><a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj159975">Clear()</a>&nbsp;&nbsp; - Clears a cache.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Memcache Protocol Support</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The preview release of Azure cache supports memcache protocol (both binary and text). Azure cache has many advantages over memcached. With this protocol support, existing applications that were using memcache can migrate easily to Azure and leverage the benefits of Azure Cache.</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://msdn.microsoft.com/en-us/library/windowsazure/hh914167">MSDN</a> has more info on how to enable memcache protocol support. I'll expand on the protocol differences between memcache and Azure Cache in a later post.</p>
<p>&nbsp;</p>
<p><strong>Appfabric Cache Feature Parity</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; All the familiar features of Appfabric Cache (high-availability, notifications, regions, tags etc) can be used with the Azure Cache preview. One exception to this is <a href="https://msdn.microsoft.com/en-us/library/hh377669.aspx">Read-Through/Write-Behind</a> capability. This is not yet supported in the preview.</p>
<p>&nbsp;</p>
<p><strong>Improved Performance</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; There were a lot of under-the-hood changes to improve the performance (both latency and throughput) of Azure cache.</p>
<p>&nbsp;</p>
<p>Access to Azure shared cache goes through a LoadBalanced input endpoint which has impact both on latency and throughput (more on this in a later blog). In the preview release, there is no need to go through a load balanced endpoint since the cache role is in the same deployment as the application, the application can use internal endpoints to connect to the cache role instances.</p>
<p>&nbsp;</p>
<p>Also, as part of this preview, we implemented a more efficient wire protocol between the cache client and servers that has given us good results.</p>
<p>&nbsp;</p>
<p>The above changes provide significant latency and throughput improvements compared to the Azure shared cache.</p>
<p>&nbsp;</p>
<p><strong>Improved Management Experience</strong></p>
<p>You can manage the azure cache preview roles just like you manage any other azure application. You can use the service management APIs to increase/decrease the number of cache role instances. You can also monitor a rich set of performance counters to help understand how the cache is performing for your application.</p>
<p>&nbsp;</p>
<p>You can remote desktop to the cache role instances to look at the cache perf counters, or configure the list of performance counters to collect through <a href="https://msdn.microsoft.com/en-us/library/windowsazure/hh914135#BKMK_EnablePerfCounter">code</a></p>
<p>&nbsp;</p>
<p><strong>Useful Links</strong></p>
<p>&nbsp;</p>
<p>Here are a few links that I've found useful in getting started on the azure cache preview.</p>
<p>&nbsp;</p>
<ol>
<li value="1"><a href="https://msdn.microsoft.com/en-us/library/windowsazure/gg278356"> MSDN's Azure Caching section </a> has a lot of good info about the preview release.</li>
<li>You can watch Shyam Seshadri's <a href="https://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/AZR309">presentation</a> at TechEd about these enhancements.</li>
<li><a href="https://blogs.msdn.com/b/windowsazure/archive/2012/06/25/cloud-services-series-what-s-new-in-windows-azure-caching.aspx">Prashant Kumar's blog</a> also gives a good overview of what is new in Azure caching.</li>
</ol>
<p>&nbsp;</p>
<p>Over the next few weeks, I plan to do a deep dive into many of the above aspects of Azure Cache Preview.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>