SharePoint Site Caching improvement

SharePoint Site Caching is very important for fast response. Distributed Cache in SharePoint is good, but after some time, its content becomes old. The first user who visits specific SharePoint Site, which was not visited for longer time, has to wait many seconds that Site Web Page opens, because Distributed Cache has to refresh its content. This is not optimal user experience and could be annoying.

 

Solution:

 

You solve the problem by creating a script that would run on a schedule.

One option is to open specific Site Web Page in browser, but it is problematic, because in this case I have to run specific browser many times and script will probably fail on long run.

Better option is to use WebClient.DownloadString Method, which can download Web Page as string.

 

First of all, you have to enable access to SharePoint Site from the same machine, where SharePoint is hosted. Windows Server has integrated loopback security feature that prevents you to access SharePoint Site from SharePoint hosted Server. You can enable access to SharePoint Site using Registry (regedit.exe).

You have to find registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0

and add registry Multi-String Value:

BackConnectionHostNames with all desired FQDN from which you want to access SharePoint Sites (for instance spca.contoso.com, sp.contoso.com, …).

 

BackConnectionHostNames

 

You have to restart SharePoint server to apply upper settings. SharePoint Sites from above list should be accessible using browser (Internet Explorer) on SharePoint server.

 

Next, you have to create PowerShell script (for instance OpenSP.ps1), that is needed to download Web Page as string:

$webclient = new-object System.Net.WebClient
$webClient.UseDefaultCredentials = $true
$webpage = $webclient.DownloadString(“https://sp.contoso.com”)

 

Above script should be run as user that has rights to open SharePoint Web Site (for instance Contoso\SPAdmin). User’s credentials will be provided while opening SharePoint Web Site.

You can’t provide specific credentials in script, because using Windows Authentication SharePoint Site will never authenticate specified user.

 

Save PowerShell script in Windows Folder (for instance C:\Scripts).

 

In the last step you have to create a task using Windows Server Task Scheduler.

A task should be run as user account that has rights to open SharePoint Web Site (Contoso\SPAdmin) and it should run whether user is logged on or not.

A task is triggered every hour indefinitely (you can select different scheduler).

In Task Action, you select to run a program: PowerShell.exe with arguments: -ExecutionPolicy Bypass “C:\Scripts\OpenSP.ps1”

 

Task Action

 

You can download xml file, that you can use to import sample Task into Task Scheduler:

Open sp.contoso.com.xml.

 

That’s all. SharePoint Site Caching is optimized. Now users will not have problems visiting SharePoint Site anymore!!! 🙂

 

You can use the same script to refresh different Web Pages, when you see that it could be useful.

Written by Simon Abolnar
I am a lecturer of Informatics subjects at Higher Vocational College at the School Center Nova Gorica, located in Slovenia-EU. I have been a System Administrator of Microsoft Servers at SCNG for over 20 years.