Managing and Configuring Distributed Cache in SharePoint 2013.


There are many articles available in several blog sites that talks about Distribution Cache in detail. In this blog I will only discuss about how you can review and extend to scale-up your existing Distributed Cache configurations through Central Admin and PowerShell Command in your SharePoint 2013 environment.  Refer to http://technet.microsoft.com/en-us/library/jj219700.aspx#cache to have a better understanding on Distributed cache in SharePoint 2013.
From central admin you can verify what servers are running Distributed Cache.
*Note that it is not recommended to have Distributed Cache running on server along with Excel Services, Project Server and Search Service.
Following is the PowerShell command to verify Cache Hosts enabled in the Cache Cluster.
*Service Status information (UP or DOWN) indicates if the Cache Host is active or not.
Get-Cache Command will give list of Cache Names in the Cache-Host.
PS C:\> Get-Cache | ft -Autosize
Following command gives Cache Accounts
PS C:\> Get-CacheAllowedClientAccounts
Execute following Command if you want to know the Cache Size allocation on the Cache Host. Where VM2SP is the Server Name.
Get-AFCacheHostConfiguration -ComputerName VM2SP -CachePort "22233"

You can increase size of the Cache with the following PowerShell Command.
Update-SPDistributedCacheSize -CacheSizeInMB CacheSize 
Update-SPDistributedCacheSize -CacheSizeInMB 300 


To add a server (CacheHost)
To remove a server (CacheHost)
To stop (but not remove) the Distributed Cache service from Central Administration:
To stop (but not remove) the Distributed Cache service using PowerShell
Stop-SPDistributedCacheServiceInstance –Graceful 
To stop (but not remove) the Distributed Cache service using PowerShell
Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance

To Un-Provision the Distributed Cache service by using Windows PowerShell:
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($.service.tostring()) -eq $instanceName -and ($.server.name) -eq $env:computername}
$serviceInstance.Unprovision()


Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache 

To Change-the-Service Account use the following Script.
$farm = Get-SPFarm
$cacheService = $farm.Services | where {$_.Name -eq “AppFabricCachingService"}
$accnt = Get-SPManagedAccount -Identity domain_name\user_name
$cacheService.ProcessIdentity.CurrentIdentityType = "SpecificUser"
$cacheService.ProcessIdentity.ManagedAccount = $accnt
$cacheService.ProcessIdentity.Update()
$cacheService.ProcessIdentity.Deploy()


To Repair a cache host
During installation, configuration, or maintenance activities, the Distributed Cache service might enter a non-functioning state. Evidence of a malfunctioning Distributed Cache service will appear in Health Rules in Central Administration, or when users use features in SharePoint Server 2013 that rely on the Distributed Cache. For example, the Newsfeed on a user's My Site will start reporting errors. Also, administrators might receive the error message "cacheHostInfo is null " when they run Windows PowerShell cmdlets to manage the Distributed Cache service.
Use the following procedure to restore a non-functioning Distributed Cache host.
  1. At the Windows PowerShell command prompt, run the Get-SPServiceInstance cmdlet to list all services on all servers in the server farm. Make note of the GUID in the ID property of the Distributed Cache service on the server that you are repairing. The Get-SPServiceInstance cmdlet lists all services on all servers in the server farm. Ensure that you note the correct GUID from the server that you are repairing.
  2. At the Windows PowerShell command prompt, run the following command:
$s = Get-SPServiceInstance GUID
$s.delete()
Where GUID is the GUID of the Distributed Cache service noted in step 1.
  1. At the Windows PowerShell command prompt, run Add-SPDistributedCacheServiceInstance to reinstall and start the Distributed Cache service on the cache host that you are repairing.
Other Important things you should know about Distributed Cache are
In a stand-alone server deactivate AppFabric. Distributed cache in a single environment is not really that useful.
Please note that, Microsoft do not recommend following services and application be running on the same server running Distributed Cache service.


If you have a small farm with Front End Server and an App Server, enable Distributed Cache Service on Web Front End Server and Stop/unprovision Distributed Cache Service on Application Server.


Minimum number of CachHosts per form are at least one.
When adding a New Server to the farm, and you can do same if you don’t want that server as Distributed Cache host to be part of the cache cluster.
Run Config Wizard with SkipRegisterAsDistributedCacheHost
PS C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\BIN>
.\PSCONFIG.EXE -cmd Configdb create SkipRegisterAsDistributedCacheHost
Connect-SPConfigurationDatabase -DatabaseServer "ServerName\InstanceName" -DatabaseName "SharePointConfigurationDatabaseName" -Passphrase (ConvertTo-SecureString "MyP@ssw0rd") -AsPlainText -SkipRegisterAsDistributedCacheHost –Force
SkipRegisterAsDistributedCacheHost:By default all the servers in the farm are registered as a cache host (that is, DistributedCacheService is running by default). Use this parameter to not register the server computer as a distributed cache host. If you want to have a dedicated cache host, then use this parameter to make sure that caching service is not installed on the computer.