Calculate and Set Distributed Cache Size

#calculation from: https://technet.microsoft.com/en-us/library/jj219613.aspx

$membanks =get-wmiobject Win32_PhysicalMemory

$sum = 0

$i=1

foreach ($membank in $membanks)

{

 write-host "Capacity Memory $i = " ($membank.capacity/1024/1024)

 $sum = ($membank.capacity/1024/1024) + $sum

 $i=$i+1

}

 

write-host "Sum of Memory = " $sum

 

$cachesize = ($sum - 2048)/2

if ($cachesize>16384)

 {

  $cachesize=16384 #not more than 16GB

 }

 

write-host "Distributed Cachesize will be updated to: " $cachesize

Update-SPDistributedCacheSize -CacheSizeInMB $cachesize

Comments

  • Anonymous
    January 01, 2003
    Hi Nik, Doing that on all servers from one PS Window could be a little tricky, because I have to check if PS Remoting is correctly configured, FW Ports are open.... Stopping and Starting is a great idea. I'll change the script here as soon as I've time!

  • Anonymous
    September 20, 2013
    Nicely automated script to set DS memory max to 16 GB.. How about stopping servers and starting Distributed Cache service on server before and after setting cache size? How about supporting this script for multiple cache host in servers? Please don't take this as critical comment.. Overall, you have done great job posting this script. I may able to extend your script to some of the concerns I have mentioned in this comment...

  • Anonymous
    September 20, 2013
    One more note for readers of this blog, Please stop Distributed Cache service on all servers in farm, Run this script from only 1 server in farm, and Start Distributed Cache service on required servers in farm.

  • Anonymous
    February 24, 2014
    Handy tip.
    Instead of the " / 1024 /1024" , you can just change it to " / 1MB" to convert to MB. (Ditto for GB, etc.)

  • Anonymous
    October 24, 2014
    PS typo in script. Should be: if ($cachesize -gt 16384)

  • Anonymous
    June 03, 2015
    Works well. It might be good to point out that this is mainly useful for servers that are going to be dedicated Distributed Cache servers. And you might want to leave more than 2 GB for the OS because you may have backup jobs and antivirus process and other processes that might want a little RAM too. For SharePoint servers that are not dedicated to distributed cache duties, the guidance athttps://technet.microsoft.com/en-us/library/jj219572.aspx still says the recommended cache size is 1 GB for a small farm (less than 10,000 users), is 2.5 GB for a medium farm (less than 100,000 users), and 12 GB for a large farm (less than 500,000 users).