Monday, March 12, 2012

SharePoint server cache: How to clear

For some reasons, you have decided to clear cache.

Here are several reasons why I need to clear SharePoint server cache:

1. Workflow timer job is acting weird. Workflows are stuck in "Starting" status without any errors in ULS log.

2. User Profile application produces synchronization errors such as  failure trying to synch site . Cannot insert duplicate key row in object

3. You have restored your VM with SharePoint Server and having errors like this:  System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.Administration.SPDatabase.get_SqlSession()

So, how do you clear the SharePoint cache?

1. Stop SharePoint Timer

2. Check the GUID for your config database:

Go to - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure\ConfigDB
and Check ID

For SP2013 - it's 15.0 folder instead 14.0
And any case, this step is optional and you can try to locate cache folder without investigation ID.

3. Go to {You system drive}:\ProgramData\Application Data\Microsoft\SharePoint\Config 
Clear the files from folder with the ID of your config db.
Create cache.ini with the value '1' in the file

4. Start SharePoint Timer

5. Check the cache.ini. If caching started successfully you will see that:
 - cache.ini contains other value than '1'
 - new xml files were created.

P.S. I have noticed that SharePoint 2010 creates another folder with files PERSISTEDFIle extension.
I have deleted this folder  and haven't discovered any problem after that. Although, I found a post where it says that
be sure NOT to touch the one with the PERSITEDFILEs
(Clear the SharePoint Configuration (Timer) Cache)

Please, please, please, SharePoint community if you know why SharePoint uses this PERSITEDFILE, let me know.