Enabling the Anonymous search results cache can help you improve the performance of your SharePoint 2013 public-facing website using the search-driven publishing model. So how do you ensure that your website is using the Anonymous search results cache?
Search-driven publishing model in SharePoint 2013
One of the new capabilities of SharePoint 2013 is the search-driven publishing model. By leveraging the capabilities of SharePoint 2013 Search you can publish content from one or more sources to your public-facing website.
The great benefit of using the new search-driven publishing model above the classic publishing approach that was available in SharePoint 2007 and 2010 is that you can build truly dynamic and personalized websites. By leveraging SharePoint 2013 Search capabilities, using the information about the current visitor you can ensure that relevant content will be displayed. This will eventually lead to increasing the conversion rate of your website.
SharePoint 2013 Search is an enterprise-class search engine. It is very powerful and offers a rich set of features but for this all to work it requires more resources than were needed for old-fashioned static websites. Luckily SharePoint 2013 offers us a number of ways to minimize the impact and improve the performance of public-facing websites amongst which the Anonymous search results cache.
Anonymous search results cache in SharePoint 2013 Search
On public-facing websites built on SharePoint 2013 and which use the new search-driven publishing model, each page request results in executing one or more search queries to retrieve the contents of that page. If you have a busy website this can lead to many search queries being executed in a short period of time. With the Anonymous search results cache SharePoint can store results of search queries requested by anonymous users so that subsequent requests of the same queries can be served from cache lowering the load on your servers and improving the performance of your website.
Whether you want to use the Anonymous search results cache or not is configurable on a per-search query basis, which offers you great flexibility. Although the Anonymous search results cache is enabled by default it hasn’t always been like that. If you haven’t installed the March 2013 Public Update for SharePoint 2013 yet or you have Content Search Web Parts or Catalog Item Reuse Web Parts added before installing the March 2013 Public Update or you’re using the Search REST API with anonymous users, you might need to enable the Anonymous search results cache for all those queries.
Enabling old Content Search and Catalog Item Reuse Web Parts for Anonymous search results cache
According to the TechNet article about configuring cache in SharePoint 2013 the suggested approach to ensure that your Content Search and Catalog Item Reuse Web Parts are enabled for Anonymous search results cache is to remove the old instances of your Web Parts and re-adding them using the new Web Part definitions from the Web Part Gallery. Unfortunately this means losing all of the configuration of your Web Parts. If you are willing, you can try the following alternative approach.
In order to enable a Content Search or a Catalog Item Reuse Web Part for Anonymous search results cache the configuration of that Web Part must have the TryCache property set to true.
In order to do this, follow these steps:
- Export your Content Search/Catalog Item Reuse Web Part
- In the .webpart file move to the DataProviderJSON property
- In the Properties part of the string add "TryCache":true
- Move further to the PropertiesJSON fragment of the DataProviderJSON string
- Add \"TryCache\":true (mind the backslashes which must be added as well)
- Save the .webpart file, upload it and replace the old instance of your Web Part with the new one
Repeat the steps above for every single Content Search and Catalog Item Reuse Web Part on your website. This applies only to Web Parts that issue queries themselves. Web Parts that use Shared Data Provider don’t require to be modified.
Following screenshot shows the value of the DataProviderJSON property with the Anonymous search results cache enabled:
Although you might be considering scripting the modification approach, the API required to apply the modifications is unfortunately internal and therefore inaccessible to your code. The only way to do this in an automated fashion, is to either use reflection to access the internal types or to apply the modifications directly to the serialized JSON object which is error-prone.
Enabling SharePoint 2013 Search REST calls for Anonymous search results cache
You can benefit of the Anonymous search results cache not only within Content Search and Catalog Item Reuse Web Parts but also when using the Search REST API. This allows you to optimize the performance of your public-facing website even further.
As you know, in order to enable the SharePoint 2013 Search REST API for anonymous users, you have to create a Query Properties Template file. The exact configuration steps are described in my article dedicated to configuring SharePoint 2013 Search REST API for anonymous users.
A part of the configuration process is creating the queryparametertemplate.xml file containing common parameters for anonymous REST API queries. Since crafting this file all by yourself would be tedious I provided you with a template that you can use as a starting point. Back when I was writing the article, the template file didn’t contain the necessary configuration entries for the Anonymous search results cache. For consistency with this article and Microsoft’s recommendations I have updated the template file and added the TryCache property to it.
In order to enable your Search REST queries for the Anonymous search results cache you have to add the TryCache property to the Properties section:
<a:KeyValueOfstringanyType> <a:Key>TryCache</a:Key> <a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value> </a:KeyValueOfstringanyType>
Following screenshot presents the updated Properties section of the queryparametertemplate.xml file:
Verifying if the Anonymous search results cache is working
Having updated the configuration of all Content Search and Catalog Item Reuse Web Parts and the queryparametertemplate.xml file for Search REST queries the last step is to verify that everything is working correctly. For this you will have to set the logging for the QueryCache category to Verbose.
If you now open the ULS log and browse to a page on your website using either a Content Search Web Part, Catalog Item Reuse Web Part or issuing a Search REST query, you should see a number of entries with the QueryCache category:
When issuing a particular query for the first time you will see that it has been executed and stored in the cache:
If everything works correctly subsequent calls should be retrieved from the search results cache:
One of the new capabilities of SharePoint 2013 is the search-driven publishing model which allows you for building dynamic and personalized websites. To minimize the impact of using the search-driven publishing model on busy public-facing websites with anonymous access using you can use the the Anonymous search results cache.