Distributed Cache Service Management – Typical Use Cases and Crib Sheet

As many of us (read SharePoint Admins) might know, even with all the benefits and SharePoint 2013’s dependence on Distributed Cache, it’s been really touchy and can make or break your beautifully architected SharePoint farm. Even harmless reboot of server or patching downtime for one server, can destroy Distributed Cache cluster and unstablize SharePoint farm.

In addition to Microsoft’s outstanding TechNet resource to manage the Distributed Cache service in SharePoint Server 2013, I have been maintaining my own crib sheet to manage Distributed Cache Service, which might become handy for many of SharePoint admins out there. Here are the high level scenarios and use cases for Distributed Cache Service management. Hopefully this cheat sheet will help you to manage distributed cache, fine tune or revive if it’s ever dead.

Common Management Scenarios

  • Set the context of your PowerShell session to a particular cache cluster – You must run this command before using any other Cache Administration commands in PowerShell mentioned in this article

Use-CacheCluster

  • View Cache Cluster Info – Provides information regarding number of cache hosts in cache cluster and how many of them are running Distributed Cache, Run this command directly from Cache host, this should be one of the first command I would run to see status of Distributed Cache Cluster on the SharePoint farm.

Get-CacheHost

  • Add the Cache host to the Distributed Cache Cluster – If you don’t see Distributed Cache service on the Services on Server Page, run following command from the Cache host, You can also use this command to Add cache host on the cache cluster, You must run this command to add cache host to the cluster, if you have stopped cache host using “Remove-SPDistributedCacheServiceInstance” for patching or repairing server. please note that this command would reset the cache size to 5%

Add-SPDistributedCacheServiceInstance

  • Remove the Cache host from the Distributed Cache Cluster – Plan to stop the cache host gracefully for patching and remove the server from the host, Do not use this approach to stop the server if you need to update cache memory size. Instead manually start/stop Distributed Cache service from Service on Server page or start/stop service instance using PowerShell command. Please note that running this command will completely remove Distributed Cache service from Services on Server page on Central Admin. If you ever come across scenario where Distributed Cache not showing on Services on Server page, someone must have ran this command on the Cache host.

Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance

  • Start the Distributed Cache Service instance on Server – Run this command directly from Cache host, This will start Distributed Cache service on Central Admin Services on Server Page and starts App Fabric Cache windows service on the Cache host. This is same as starting Distributed Cache service from Services on Server page on Central Admin.

$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Provision()

  • Stop the Distributed Cache Service instance on Server – Run this command directly from Cache host, This will stop Distributed Cache service on Central Admin Services on Server Page and disable App Fabric Cache windows service on the cache host. This is same as stopping Distributed Cache service from Services on Server page on Central Admin.

$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Unprovision()

  • Repair the Distributed Cache host – If you ever come across error like cacheHostInfo is null while running any of Distributed Cache commands from Cache host, try to delete Distributed Cache service from the server and run Add-SPDistributedCacheServiceInstance to add Cache host to the cluster

$instance = “SPDistributedCacheService Name=AppFabricCachingService”;
$service = Get-SPServiceInstance |?{($_.service.tostring()) -eq $instancename -and ($_.server.name) -eq $env:COMPUTERNAME};
$service.delete();

Understanding these commands has helped me revive dead Distributed Cache environment. Over the time, I am planning to maintain this crib sheet as I learn more about managing Distributed Cache. This would be my reference in case I need to fix or revive Distributed Cache service on SharePoint farm.

Additional References

Advertisements
This entry was posted in Distributed Cache, SharePoint Features, SP2013 Admin. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

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 )

Google+ photo

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

Connecting to %s