SharePoint: Configure the Distributed Cache Service (AppFabric)


Distributed Cache Service
Distributed Cache Service

The Distributed cache Service or AppFabric is a new component included with SharePoint 2013, you can read more about the service here and here.

By default when SharePoint 2013 installs the service, it gets allocated 10 percent of the total RAM available.

When you’re building an all-up developer or test VM, as part of other optimizations, you may want to reduce that somewhat to create  more RAM available for all the other services and processes.

The Powershell script below will configure the Distributed Cache Service to use 100MB of ram

Clear-Host

# Load SharePoint PowerShell snapin
Write-Host
Write-Host "(1) Verify SharePoint PowerShell Snapin Loaded" -ForegroundColor White
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.PowerShell'}
if ($snapin -eq $null) {
	Write-Host "    ..  Loading SharePoint PowerShell Snapin" -ForegroundColor Gray
    Add-PSSnapin -Name "Microsoft.SharePoint.PowerShell"
}
Write-Host "    Microsoft SharePoint PowerShell snapin loaded" -ForegroundColor Gray

# Load the Active Directory snapin
Write-Host
Write-Host "(2) Verify ActiveDirectory Snapin Loaded" -ForegroundColor White
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'ActiveDirectory'}
if ($snapin -eq $null) {
	Write-Host "    ..  Loading ActiveDirectory Snapin" -ForegroundColor Gray
    Import-Module "ActiveDirectory"
}
Write-Host "    ActiveDirectory snapin loaded" -ForegroundColor Gray

Write-Host
Write-Host "(3) Get Fully Qualified Domain Name" -ForegroundColor White
$dnsroot = '.' + (Get-ADDomain).dnsroot
$fqdn = $env:COMPUTERNAME + $dnsroot
Write-Host "    '$fqdn'" -ForegroundColor Gray

Write-Host
Write-Host "(4) Configure Distributed Cache Service (AppFabric) to 100MB" -ForegroundColor White

Use-CacheCluster
Write-Host "    Checking..." -ForegroundColor Gray
Get-CacheHostConfig -ComputerName $fqdn -CachePort 22233

$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
Write-Host "    Got service..." -ForegroundColor Gray
$serviceInstance
Write-Host "    Stopping..." -ForegroundColor Gray
$serviceInstance.Unprovision()
Write-Host "    Configuring..." -ForegroundColor Gray
Set-CacheHostConfig -Hostname $fqdn -cacheport 22233 -cachesize 100
Write-Host "    Starting..." -ForegroundColor Gray
$serviceInstance.Provision()

Write-Host "    Checking..." -ForegroundColor Gray
Get-CacheHostConfig -ComputerName $fqdn -CachePort 22233

Write-Host "    Configured Distributed Cache Service (AppFabric)" -ForegroundColor White

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.