Optimize or disable the Prefetch caches
Applies to |
Content Delivery, Content Management |
---|
The Prefetch caches are initially populated on application startup and continue to be populated during the lifetime of the application. The list of items to prefetch is defined for each database in the configuration files in the <wwwroot>/App_Config/Prefetch/
folder.
Read more about optimizing and disabling the initial population of the Prefetch caches in the Excessive load on the Core database after application restart knowledge base article.
Prefetching too many items increases the load on the SQL server and can degrade application startup time. To avoid this, you can:
-
Optimize the initial population of the Prefetch caches.
-
Disable the initial population of the Prefetch caches.
Optimize the initial population of the Prefetch caches
You optimize the initial population of the Prefetch caches by only including the most frequently accessed items.
Use the following elements to determine which items are included:
Element |
Description |
Multiple elements allowed |
---|---|---|
|
This element includes all items based on a specific template. |
Yes |
|
This element includes the specified item. |
Yes |
|
This element includes the child items of a specified item. |
Yes |
|
This element limits the number of child items that can be cached for each parent item. |
No |
The following is a sample patch file containing the Prefetch caches configuration elements:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:set="http://www.sitecore.net/xmlconfig/set/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore>
<databases>
<database id="web">
<dataProviders>
<param desc="headProvider">
<dataProvider param1="$(id)">
<prefetch hint="raw:AddPrefetch">
<template desc="sample">{<template GUID="">}</template>
<item desc="root">{<item GUID="">}</item>
<children desc="main sections">{<item GUID="">}</children>
<childLimit>100</childLimit>
</prefetch>
</dataProvider>
</param>
</dataProviders>
</database>
</databases>
</sitecore>
</configuration>
Use groups to split prefetching requests
You can use groups to speed up the initial population of the Prefetch caches and prevent database timeout exceptions.
By default, the initial population of the Prefetch caches runs as a single SQL request. You can split this initial population into several parallel requests by grouping elements.
You can group elements using the group
attribute. You can use the group
attribute with the template
, item
, and children
attributes.
The elements from the same group and element type are prefetched together. If an element's group
attribute is not specified, then the default group is used.
The following is a sample that prefetches the ui
group and dictionary
group as two separate requests run in parallel:
<template group="ui" desc="tool button new line">{6400BD3F-E8A1-4C38-8319-131448492439}</template>
<template group="ui" desc="toolbar">{3A1A3B48-3434-4E5A-8F05-AD6E1687D888}</template>
<template group="dictionary" desc="dictionary folder">{267D9AC7-5D85-4E9D-AF89-99AB296CC218}</template>
<template group="dictionary" desc="dictionary entry">{6D1CD897-1936-4A3A-A511-289A94C2A7B1}</template>
Disable the initial population of the Prefetch caches
If you disable the initial population of the Prefetch caches, they are still populated when items are accessed by visitors.
To disable the initial population:
-
Replace all element under the
configuration/sitecore/databases/database/dataProviders/dataProvider/prefetch
elements with a<patch:delete />
element. -
Add an new
<prefetch>
element with the following global elements:Element
Description
Mandatory
<cacheSize>
This element configures the maximum initial Prefetch cache size. If it is not specified, it defaults to the value of the
Caching.DefaultDataCacheSize
setting.No
<childLimit>
This element limits the number of child items that can be cached for each parent item.
Yes
<logStats>
When this element is set to
true
, advanced diagnostics information is logged as:RequestResponseCount: <number of added items>, Template: <template GUID>
Yes
The following is a sample patch file containing the Prefetch caches configuration elements:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:set="http://www.sitecore.net/xmlconfig/set/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore>
<databases>
<database id="web">
<dataProviders>
<param desc="headProvider">
<dataProvider param1="$(id)">
<prefetch hint="raw:AddPrefetch">
<patch:delete />
</prefetch>
<prefetch hint="raw:AddPrefetch">
<cacheSize>1000MB</cacheSize>
<childLimit>100</childLimit>
<logStats>false</logStats>
</prefetch>
</dataProvider>
</param>
</dataProviders>
</database>
</databases>
</sitecore>
</configuration>