Installing AppFabric Cache
In this task you will install and configure
Windows Server AppFabric Cache.
WindowsServerAppFabricSetup_x64_6.1.exe
2.
Selected and Installed Caching Services
and Cache Administration.
3.
Configured Caching Service and created to New
cluster with 1-5 machines .
Using
the Cache API
I have created a
new named Cache, we are going to write a simple SharePoint Web Part that
reads/writes data in the cache. You can of course store any serializable .NET
object in the cache. To use the Cache you need to reference the Cache client
assemblies.
1.
Microsoft.ApplicationServer.Caching.Core.dll
is the Cache’s base library, referenced by both the Cache’s client layer and
server layer. It contains things like the configuration libraries and base
Cache types.
2.
Microsoft.ApplicationServer.Caching.Client.dll contains the Cache’s client library, which is
the API that connects to the Cache cluster to store and retrieve data.
AppFabric cache
configuration inthe web.config file
XML
<configSections>
<section name="dataCacheClient"
type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,
Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</configSections>
<dataCacheClient>
<hosts>
<host name="hostname" cachePort="22233" />
</hosts>
</dataCacheClient>
3. There's a public
method named GetCachedName that returns a string. Inside of that method,
you will get the DataCacheFactory , and then look for a key in the Lab1Cache
named
C#
public
string GetCachedName()
{
string name = null;
string key = "ApplicationName";
dcf = new DataCacheFactory();
if (dcf != null)
{
var cache =
dcf.GetCache("Lab1Cache");
name = cache.Get(key) as
string;
if (name == null)
{
name = "Windows Server
App Fabric Cache Lab";
cache.Put(key, name);
}
else
{
name += " From
Cache!";
}
}
return name;
}
Using
the AppFabric Cache ASP.NET Session State Provider in SharePoint 2010
·
If you have already used ASP.NET session state to
store user activity data, you can just change the web.config sessionState
binding and have the Cache take over storing ASP.NET Session State across the
cache cluster. This enables you to simply add scale and performance without any
code changes to your existing web applications.
1.
Execute the Get-CacheHost cmdlet to see
the state of your cache cluster.
·
PowerShell
·
Get-CacheHost
You should see
something that looks similar to the following Figure. Note that the Service
Status is Down
1.
Use the $myhost.HostName and $myhost.PortNo
properties as the input to Start-CacheHost.
·
PowerShell
·
$myhost =
Get-CacheHost
·
Start-CacheHost
$myhost.HostName $myhost.PortNo
You should see
something that looks similar to following Figure . Note that the Service
Status is UP
·
·
2.
Configure the underlined SharePoint Web App to
use the AppFabric Cache ASP.NET Session State Provider. Web.Config file
XML
·
<sessionState
mode="Custom" customProvider="SessionStoreProvider">
·
<providers>
·
<add
name="SessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider,
Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" cacheName="Lab1Cache" />
·
</providers>
·
</sessionState>
Understand
the ramifications of moving session out of process.
Once you move
session state outside of the web server process, all the objects you put in the
Session need to be serializable.