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

Cover Image for Year in Review: 2022

Year in Review: 2022

> Full steam ahead

Cover Image for Content Editor Search Bar Not Working

Content Editor Search Bar Not Working

> Sometimes it works, sometimes not

Cover Image for Tips for New Sitecore Developers

Tips for New Sitecore Developers

> Because learning Sitecore can be hard

Cover Image for JSS + TypeScript Sitecore Project Tips

JSS + TypeScript Sitecore Project Tips

> New tech, new challenges

Cover Image for NextJS: Access has been blocked by CORS policy

NextJS: Access has been blocked by CORS policy

> CORS is almost as much of a nuisance as GDPR popups

Cover Image for Don't Ignore the HttpRequestValidationException

Don't Ignore the HttpRequestValidationException

> Doing so could be... potentially dangerous

Cover Image for NextJS: Unable to Verify the First Certificate

NextJS: Unable to Verify the First Certificate

> UNABLE_TO_VERIFY_LEAF_SIGNATURE

Cover Image for Script: Boost SIF Certificate Expiry Days

Script: Boost SIF Certificate Expiry Days

> One simple script that definitely won't delete your system32 folder

Cover Image for Hello World

Hello World

> Welcome to the show

Cover Image for SPE Script Performance & Troubleshooting

SPE Script Performance & Troubleshooting

> Script never ends or runs too slow? Get in here.

Cover Image for Super Fast Project Builds with Visual Studio Publish

Super Fast Project Builds with Visual Studio Publish

> For when solution builds take too long

Cover Image for How to Run Old Versions of Solr in a Docker Container

How to Run Old Versions of Solr in a Docker Container

> Please don't make me install another version of Solr on my local...

Cover Image for Tips for Forms Implementations

Tips for Forms Implementations

> And other pro tips

Cover Image for NextJS/JSS Edit Frames Before JSS v21.1.0

NextJS/JSS Edit Frames Before JSS v21.1.0

> It is possible. We have the technology.

Cover Image for Ideas For Docker up.ps1 Scripts

Ideas For Docker up.ps1 Scripts

> Because Docker can be brittle

Cover Image for NextJS: Short URL for Viewing Layout Service Response

NextJS: Short URL for Viewing Layout Service Response

> Because the default URL is 2long4me

Cover Image for Tips for Applying Cumulative Sitecore XM/XP Patches and Hotfixes

Tips for Applying Cumulative Sitecore XM/XP Patches and Hotfixes

> It's probably time to overhaul your processes

Cover Image for Add TypeScript Type Checks to RouteData fields

Add TypeScript Type Checks to RouteData fields

> Inspired by error: Conversion of type may be a mistake because neither type sufficiently overlaps with the other.

Cover Image for On Sitecore Stack Exchange (SSE)

On Sitecore Stack Exchange (SSE)

> What I've learned, what I see, what I want to see

Cover Image for Early Returns in React Components

Early Returns in React Components

> When and how should you return early in a React component?

Cover Image for Symposium 2022 Reflections

Symposium 2022 Reflections

> Sitecore is making big changes

Cover Image for Sitecore Symposium 2022

Sitecore Symposium 2022

> What I'm Watching 👀

Cover Image for On Mentorship and Community Contributions

On Mentorship and Community Contributions

> Reflections and what I learned as an MVP mentor

Cover Image for JSS: Reducing Bloat in Multilist Field Serialization

JSS: Reducing Bloat in Multilist Field Serialization

> Because: performance, security, and error-avoidance