Caring for Distributed Cache is a task that should be on SharePoint Server Administrator list every month, but it’s a little forgotten. Usually we remember it only when something else fails, for example, incoming mail to the portal or search engine is not working. Although we do not need to shut down the server for the repair of defective caches, we can only repair the service and it can be corrected even in the morning, it is not recommended to ignore these errors. If distributed cache is too corrupted, it can be such a pity that we need to re-install the SharePoint server, which nobody wants.
It’s recommended to use powershell with Sharepoint management shell, but by no means re-start the AppFabric caching Service manually.
Configuration preview
use-cachecluster get-AFCacheHostConfiguration get-cachehost
Odstranjevanje/dodajanje host-a
It’s always useful to first stop the service and then remove it from a specific server. Start the commands on the server where we want to remove the distributed cache host or to repair its operation.
stop-SPDistributedCacheServiceInstance remove-SPDistributedCacheServiceInstance Add-SPDistributedCacheServiceInstance
FIX – cacheHostInfo is null
If the above commands do not work and throws an error cacheHostInfo is null
$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
$serviceInstance.Delete()
Add-SPDistributedCacheServiceInstance
$cacheClusterInfo.CacheHostsInfoCollection
These commands fix the Host info so that we can re-add to the Distributed Cache Service server using the command
Add-SPDistributedCacheServiceInstance
Fix – Error Starting Distributed Cache instance
First, we have to remove DC from server
Stop-SPDistributedCacheServiceInstance –Graceful Remove-SPDistributedCacheServiceInstance$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}$serviceInstance.delete()
Secondly, we add DC back on the server
$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
$serviceInstance.Delete()
Add-SPDistributedCacheServiceInstanceFix – Invalid provider and connection string read
Sometimes registry entries are blank for Provider and string. So we add them manually to register
HKEY_LOCAL_MACHINE >> SOFTWARE >> MICROSOFT >> AppFabric >> V1.1 >> CONFIGURATION
Connection String:
Data Source=spsql;Initial Catalog=SPFarm_SharePoint_Config;Integrated Security=True;Enlist=False
(spsq – name of your’s SQL server with SharePoint databases)
Provider:
SPDistributedCacheClusterProvider
Admin Configured in Service configured have value 0
Than we use this command again to check configuration
use-cachecluster
and of course
get-cachehost
Remember: you should never manually launch the AppFabric caching Service on the server, always through the powershell commands!
Distributed cache is important for the performance of some other services on SharePoint – the most value service is certainly a search engine and search is not working without DC.
Another tip: You save the AppFabric configuration when its working well so that a functioning configuration can easily be imported when distributec cache have errors.