Friday, 10 April 2015

AppFabric Command

This are a list of useful command that I've gathered while developing custom web part under SharePoint 2013. This is a distributed cache services command and I've developed my custom web part to use this services. I'm aware that Microsoft didn't support custom development against this distributed cache services. But I need a simple cache solution to support our custom application under SharePoint farm.

​Remove Distributed Cache

Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance

Host not found when issuing Remove command above

$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 a server and Start Distributed Cache service

Add-SPDistributedCacheServiceInstance

Stop distributed cache service instance

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

Start distributed cache service instance

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

Add cache

New-Cache <CacheName>

Set timetolive cache data

Stop-CacheCluster
Set-CacheConfig -CacheName <cachename> -TimeToLiveMins 20
Start-CacheCluster

Remove cache

Remove-Cache <CacheName>

Get all cache available

Get-Cache | select CacheName

Get cache statistic

Get-CacheStatistics <cachename>

No comments:

Post a Comment