SharePoint 2013 layouts pages breaking with "Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode:SubStatus:The request timed out"

Here is an issue based on Distributed cache I worked on last week.

SharePoint 2013 layouts page breaks after one or more post backs and loses View State with error below.

"Unexpected error occurred in method 'Put' , usage 'SPViewStateCache' - Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode:SubStatus:The request timed out.. Additional Information : The client was trying to communicate with the server : net.tcp://servername:22233" 

Basically when the client was trying to communicate with the server, it was throwing following error in ULS:-

Unexpected error occurred in method 'GetObject' , usage 'SPViewStateCache' - Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out.. Additional Information : The client was trying to communicate with the server : net.tcp://servername:22233   
 at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)   
at Microsoft.ApplicationServer.Caching.DataCache.InternalGet(String key, DataCacheItemVersion& version, String region, IMonitoringListener listener)  
 at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass49.<Get>b__48()   
 at Microsoft.SharePoint.DistributedCaching.SPDistributedCache.GetObject(String key)'.

First I ran following commands to see the health of distributed cache includes the status.

 

$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName)
$cacheClusterInfo

To resolve the issue, I suggested to run following Power Shell commands which increases the distributed cache time out values to 10 seconds.

 

$settings = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
$settings.ChannelOpenTimeOut =10000
$settings.RequestTimeout=10000
Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache -DistributedCacheClientSettings $settings
$settingsverify = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
$settingsverify

$settingsa = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
$settingsa.ChannelOpenTimeOut = 10000
$settingsa.RequestTimeout=10000
Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache -DistributedCacheClientSettings $settingsa
$settingsaverify = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
$settingsaverify

$set = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
$set.MaxBufferSize = 33554432
Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache -DistributedCacheClientSettings $set
Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache

$set = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
$set.MaxBufferSize = 33554432
Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache -DistributedCacheClientSettings $set
Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache