Azure PaaS Cache Optimization

> App Services benefit greatly from proper configuration
Cover Image for Azure PaaS Cache Optimization

Cache yourself before you wreck yourself. - Cache Cube

Caching in Sitecore: the source of much confusion amongst developers and content authors alike.

Is the issue my code or the cache?

The cache settings in Sitecore are a critical part of the performance tuning process, and they can be a bit tricky to get right. In this post, we'll cover the basics of caching in Sitecore and how to optimize your cache settings for Azure PaaS.

High Level Optimization Steps

  1. Become familiar with the default cache sizes (the default cache sizes are smaller than what Sitecore recommends as a starting point)
  2. Set Caching.DisableCacheSizeLimits to true on your local environment to get a feel for how large your caches naturally grow to
  3. Review any existing optimizations that your solution may already have
  4. Identify caches that are too small on your upstream environments
  5. Push configuration changes to your environments
  6. Monitor logs, memory usage, and database usage
  7. Iterate and increase / decrease sizes as needed
  8. Set up continuous monitoring or schedule regular reviews of cache sizes and infrastructure load

The most reliable way to find the caches that are too small is to look at the logs in Application Insights. You can use the following Kusto Query Language (KQL) to find the offending caches:


_10
union isfuzzy=true traces
_10
| where timestamp > ago(90d)
_10
| where message contains "DefaultScavengeStrategy"
_10
| extend SubstringMessage = substring(message, 0, 65)
_10
| extend Role = tostring(customDimensions["Role"])
_10
| summarize Count=count(),
_10
MessageAny=take_any(message)
_10
by SubstringMessage, Role
_10
| project Count, SubstringMessage, Role
_10
| order by SubstringMessage asc, Count desc, Role desc

This query identifies which caches were automatically cleared via the DefaultScavengeStrategy due to hitting the max size limit, on which role (CM/CD), and how many times over the specified time period.

Mapping the Settings / Example Config

I did the hard work for you and did all the research required to map out which cache names on cache.aspx map to which settings in the Sitecore configuration. This config also separates out the cache sizes by role and database.


_82
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
_82
xmlns:role="http://www.sitecore.net/xmlconfig/role/"
_82
xmlns:set="http://www.sitecore.net/xmlconfig/set/">
_82
<sitecore>
_82
<databases>
_82
<database id="web">
_82
<cacheSizes role:require="ContentDelivery">
_82
<!-- web[paths] -->
_82
<paths>4MB</paths>
_82
<!-- web[standardValues] -->
_82
<standardValues>4MB</standardValues>
_82
</cacheSizes>
_82
<cacheSizes role:require="ContentManagement or ContentDelivery">
_82
<!-- web[items] -->
_82
<items>760MB</items>
_82
</cacheSizes>
_82
<dataProviders>
_82
<dataProvider>
_82
<param desc="headProvider">
_82
<dataProvider>
_82
<prefetch>
_82
<!-- SqlDataProvider - Prefetch data(web) -->
_82
<cacheSize>870MB</cacheSize>
_82
</prefetch>
_82
</dataProvider>
_82
</param>
_82
</dataProvider>
_82
</dataProviders>
_82
</database>
_82
<database id="master" role:require="ContentManagement">
_82
<cacheSizes>
_82
<!-- master[items] -->
_82
<items>760MB</items>
_82
<!-- master[data] -->
_82
<data>170MB</data>
_82
<standardValues>4MB</standardValues>
_82
<!-- master[itempaths] NOTE: itempaths needs to remain fully lowercase to work -->
_82
<itempaths>75MB</itempaths>
_82
</cacheSizes>
_82
<dataProviders>
_82
<dataProvider>
_82
<param desc="headProvider">
_82
<dataProvider>
_82
<prefetch>
_82
<!-- SqlDataProvider - Prefetch data(master) -->
_82
<cacheSize>1000MB</cacheSize>
_82
</prefetch>
_82
</dataProvider>
_82
</param>
_82
</dataProvider>
_82
</dataProviders>
_82
</database>
_82
</databases>
_82
_82
<settings role:require="ContentDelivery">
_82
<!-- Log singles -->
_82
<setting name="Caching.SmallCacheSize" value="2MB" />
_82
</settings>
_82
_82
<settings role:require="ContentManagement">
_82
<!-- QueryStringCache -->
_82
<setting name="Caching.TinyCacheSize" value="300KB" />
_82
<!-- clientData -->
_82
<setting name="Caching.DefaultClientDataCacheSize" value="30MB"/>
_82
</settings>
_82
_82
<settings role:require="ContentManagement or ContentDelivery">
_82
<!-- master[isLanguageFallbackValid], web[isLanguageFallbackValid] -->
_82
<setting name="Caching.IsFallbackValid.DefaultCacheSize" value="30MB" />
_82
_82
<!-- AccessResultCache -->
_82
<setting name="Caching.AccessResultCacheSize" value="1000MB" />
_82
</settings>
_82
_82
<sites>
_82
<site name="shell" role:require="ContentManagement">
_82
<!-- shell[viewState] -->
_82
<patch:attribute name="viewStateCacheSize">1600KB</patch:attribute>
_82
</site>
_82
</sites>
_82
</sitecore>
_82
</configuration>

Adjust as needed for your solution.

Stay cachey, San Diego.

-MG


More Stories