2

I have a problem with distributed cache : I am unable to get working distributed cache on my development environment, so I decide to ship my console application to my client to test my code in his environment.

I just doing a "put" and a "get" in distributed cache but I have the mysterious "temporary failure, busy network" error. I have already search one day to repair this problem (install CU 3&4 appfabric, restart, remove host from cache cluster...), without success...

I just want to know if my code is working on an environment with working distributed cache, how can I do this? :(

  • 1
    Are u using the same cache which is supporting for sharepoint servers or you have separate cache cluster for coding? – Waqas Sarwar MVP Aug 31 '16 at 22:54
  • same cache cluster on my dev, separate cache cluster on my client's environment – WWWWWWWWWP Sep 1 '16 at 16:58
1

I would recommend to get the cache cluster working on the development environment farm first, before trying to implement something in acceptance test, or worse in production.

Otherwise you don't have a clue if your implementation of cache works or not.

To get you started, you can try with my DistributedCacheClusterManager.ps1 which you DON'T RUN from top to bottom, but find the script necessary for you. I'd start with Get-CacheClusterHealt in the bottom of the script...

Enjoy!

if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
     Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

# Start by connecting to the CacheCluster
Use-CacheCluster

<# 
Didn't work? Add -Provider and -ConnectionString properties as well
Get the properties from the file "C:\Program Files\AppFabric 1.1 for Windows Server\DistributedCacheService.exe.config".
Run editor in elevated mode (Run as administrator) and look for the element
<configuration>
  <dataCacheConfig cacheHostName="AppFabricCachingService">
    <clusterConfig provider="SPDistributedCacheClusterProvider" connectionString="Data Source=<DB Server>;Initial Catalog=<Config_DB>;Integrated Security=True;Enlist=False">
#>
Use-CacheCluster –Provider "SPDistributedCacheClusterProvider" –ConnectionString "Data Source=FQDN_DababaseServer;Initial Catalog=Config_DB;Integrated Security=True;Enlist=False"

<#
Or if you're bold and it doesn't matter if you need to reinstall the server if you fail - you can add the Provider and ConnectionString
to the registry. HKLM\Software\Microsoft\AppFabric\V1.0\Configuration

Connection String:Data Source=<<SQL Server Name or Alias>>;Initial Catalog=<<SPConfigDatabase>>;Integrated Security=True;Enlist=False
Provider: SPDistributedCacheClusterProvider
#>

# List the CacheCluster
Get-CacheHost
<#
HostName : CachePort        Service Name            Service Status Version Info
--------------------        ------------            -------------- ------------
SERVER1.DOMAIN:22233        AppFabricCachingService UP             3 [3,3][1,3]
SERVER1.DOMAIN:22233        AppFabricCachingService UP             3 [3,3][1,3]
#>

# or a single host
$cachehost = Get-CacheHost -ComputerName APP1 -CachePort 22233

# Get more details using these two different types of commands which outputs the same:
Get-AFCacheHostConfiguration -ComputerName WFE1 -CachePort 22233
Get-AFCacheHostConfiguration -ComputerName WFE2 -CachePort 22233
Get-AFCacheHostConfiguration -ComputerName APP1 -CachePort 22233
Get-AFCacheHostConfiguration -ComputerName APP2 -CachePort 22233

# or
Get-CacheHostConfig -ComputerName WFE1 -CachePort 22233
Get-CacheHostConfig -ComputerName WFE2 -CachePort 22233
Get-CacheHostConfig -ComputerName APP1 -CachePort 22233
Get-CacheHostConfig -ComputerName APP2 -CachePort 22233

##### CACHE INSTANCE

# To retrieve a list of SharePoint servers running the Distributed Cache Service Instance, you can run the following PowerShell command:
# Remeber that the servers listed here isn't part of the cache cluster, they just have a running Distributed Cache Service Instance
Get-SPServer | ? {($_.ServiceInstances | % TypeName) -contains 'Distributed Cache'} | % Address

# Use the Add-SPDistributedCacheServiceInstance cmdlet to add an instance of the distributed cache 
# server to a local server. This is required to start the AppFabric service.
Add-SPDistributedCacheServiceInstance

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

# Use the Stop-SPDistributedCacheServiceInstance cmdlet to stop an instance of the distributed cache service on a local server.
Stop-SPDistributedCacheServiceInstance -Graceful

# Use the Remove-SPDistributedCacheServiceInstance cmdlet to remove an instance of the distributed cache 
# service from a local server. This is required to stop the AppFabric service.
Remove-SPDistributedCacheServiceInstance

# If you get "cacheHostInfo is null" in return, try this script. Sometimes you have to run the
# $serviceInstance.Delete() statement several times. Verify by running it again and write to host
$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()
#Write-Host $serviceInstance

Remove-SPDistributedCacheServiceInstance

# Run this command after 1 or 2 minutes
Add-SPDistributedCacheServiceInstance

##### CACHE HOST

# This adds the CahceHost from the CacheCluster
#<clusterConfig provider="SPDistributedCacheClusterProvider" connectionString="Data Source=RSDB247CL1.REG.SKANE.SE;Initial Catalog=Farm_K_WFE1_Config_prod001;Integrated Security=True;Enlist=False" />
Register-CacheHost –Provider "SPDistributedCacheClusterProvider" –ConnectionString "Data Source=RSDB247CL1.REG.SKANE.SE;Initial Catalog=Farm_K_WFE1_Config_prod001;Integrated Security=True;Enlist=False" -Account "reg\s10932" -CachePort 22233 -ClusterPort 22234 -ArbitrationPort 22235 -ReplicationPort 22236 –HostName APP1

# This removes the CahceHost from the CacheCluster
Unregister-CacheHost -HostName APP1 -ProviderType "SPDistributedCacheClusterProvider"
Unregister-CacheHost -HostName APP1 -ProviderType "SPDistributedCacheClusterProvider" –ConnectionString "Data Source=RSDB247CL1.REG.SKANE.SE;Initial Catalog=Farm_K_WFE1_Config_prod001;Integrated Security=True;Enlist=False"

# This Starts the CahceHost in the CacheCluster
Start-CacheHost –ComputerName APP1 –CachePort 22233
Remove-CacheHost

##### EXPORT/IMPORT CACHE CLUSTER CONFIGURATION

# Export the Cache Cluster configuration to editable XML.
# You can only edit properties, not register or unregister cache hosts
Export-CacheClusterConfig -path C:\Temp\CacheClusterConfig.xml

# Stop AppFabric Caching Service on all servers
Stop-CacheCluster

# Edit the XML-file
<#
    leadHostManagement="false"  <!-- SQL Server manage lead host -->
    Check account and size of host-element. Account should be the same running the service.msc
    Size should be 10% of server memory as default
#>
# Verify that AppFabric Caching Service have stopped on all servers before importing
Import-CacheClusterConfig -path C:\Temp\CacheClusterConfig.xml

# Enable Automatic start AppFabric Caching Service on all servers
Start-CacheCluster

# Verify result
Get-CacheHostConfig -ComputerName WFE1 -CachePort 22233
Get-CacheHostConfig -ComputerName WFE2 -CachePort 22233
Get-CacheHostConfig -ComputerName APP1 -CachePort 22233
Get-CacheHostConfig -ComputerName APP2 -CachePort 22233

##### CACHE INSTANCES

Get-CacheClusterHealth

# See what caches are included
Get-Cache | select CacheName
<#
default
DistributedAccessCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedActivityFeedCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedActivityFeedLMTCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedBouncerCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedDefaultCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedLogonTokenCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedSearchCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedSecurityTrimmingCache_76d4d782-a24d-4621-85fd-cfe822386b57
DistributedServerToAppServerAccessTokenCache_76d4d782-a24d-4621-85fd-cfe8223...
DistributedViewStateCache_76d4d782-a24d-4621-85fd-cfe822386b57
#>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.