Skip to Content
Technical Articles
Author's profile photo Yannick Robin

Improve Spartacus and OCC performance with CMS Rendering Cache

Problem statement

Within JS Storefront, the frequent calls to OCC for rendering CMS content can emerge as a performance bottleneck, impacting both the API server and the database.

Below is an example of stack trace that generates a CMS page on the API server.

Below is an example of query to components4components table that is executed very frequently when generating a CMS page.

SELECT uhu.selectArg0 FROM ( SELECT item_t1.PK AS selectArg0, item_t0.RSequenceNumber AS orderArg0, item_t0.PK AS orderArg1 FROM components4components item_t0 JOIN cmscomponent item_t1 ON item_t0.SourcePK = item_t1.PK WHERE ( item_t0.Qualifier = @P0 AND item_t0.TargetPK = @P1 AND item_t0.languagepk IS NULL) AND (item_t1.TypePkString IN (...) ) UNION ALL SELECT item_t1.PK AS selectArg0, item_t0.RSequenceNumber AS orderArg0, item_t0.PK AS orderArg1 FROM components4components item_t0 JOIN puigmediatagscomp item_t1 ON item_t0.SourcePK = item_t1.PK WHERE ( item_t0.Qualifier = @P493 AND item_t0.TargetPK = @P494 AND item_t0.languagepk IS NULL) AND (item_t1.TypePkString=@P495 ) UNION ALL SELECT item_t1.PK AS selectArg0, item_t0.RSequenceNumber AS orderArg0, item_t0.PK AS orderArg1 FROM components4components item_t0 JOIN puigtagscmscomp item_t1 ON item_t0.SourcePK = item_t1.PK WHERE ( item_t0.Qualifier = @P496 AND item_t0.TargetPK = @P497 AND item_t0.languagepk IS NULL) AND (item_t1.TypePkString=@P498 )) uhu order by uhu.orderArg0 ASC ,uhu.orderArg1 ASC

This article explains how to cache CMS components, CMS Slots and CMS Pages.

Effective caching practices play a pivotal role in minimizing CPU usage on both API servers and databases. By optimizing page generation times, not only does correct caching contribute to enhanced performance, but it also significantly diminishes the server-side rendering (SSR) footprint in JavaScript SSR Storefront.

Solution

CMS Component caching

SAP Commerce Cloud is configured to cache CMS components using an EhCache region called cmsRenderingCacheRegion. You can find configuration for this bean in web-content-management-system/cmsfacades-rendering-cache-spring.xml

Please note, by default CMS Rendering Cache is disabled, to enable and tune the “CMS Rendering cache“, you should change the following properties:

cms.rendering.cache.enabled # default false
cms.rendering.region.cache.size # default 20000
cms.rendering.region.cache.ttl # default 300

To see how the cache is used and tune the cache limit, you can check cmsRenderingCacheRegion entries in HAC, navigate to Monitoring > caches.

 

Note: The cache is ignored within SmartEdit in preview mode.

CMS Slot and CMS Page caching

Slots and pages are not configured and should be added to the configuration map.

Here is an example:

<alias name="customRenderingCacheKeyProviders" alias="cmsRenderingCacheKeyProviders"/>
<util:map id="customRenderingCacheKeyProviders" key-type="java.lang.String">
    <entry key="AbstractCMSComponent" value-ref="cmsItemRenderingCacheKeyProvider"/>
    <entry key="ContentSlot" value-ref="cmsItemRenderingCacheKeyProvider"/>
    <entry key="AbstractPage" value-ref="cmsItemRenderingCacheKeyProvider"/>
</util:map>

CMS Personalization

CMS rendering cache is not compatible with CMS Personalization. Before enabling it, please make sure you do not enable for components that contains personalization.

Please note, Search Restriction should be compatible.

Cache Invalidation

By default for components, the following attributes are part of the key for CMS Rendering Cache entries (see DefaultItemRenderingCacheKeyProvider): pk, modifiedtime, currentCurrency, currentLanguage.

As modifiedTime is in the key, we do not need to worry about invalidating the cache.

For slots and pages, there not explicit invalidation but the default TTL of 5 min is suitable for most of the cases.

CMS Cache vs CMS Rendering Cache

CMS Cache and CMS Rendering Cache should not be confused.

CMS Cache is used by JSP Storefront to cache HTML content of the components. CMS Rendering Cache is used by OCC to cache the CMS DTOs.

Topic

CMS Cache

CMS Rendering Cache

Description HTML cache Cache conversion Model -> Data
Documentation SAP Help Page Not documented
springId cmsCacheRegion cmsRenderingCacheRegion
handledType __CMS_CACHE__ __CMS_RENDERING_CACHE__
keyType cmsCacheKey renderingCacheKey
keyProvider cmsCacheKeyProvider cmsRenderingCacheKeyProvider
used in defaultCmsComponentRenderer

cmsRenderingCacheService

cmsComponentRenderingService

cmsPageRenderingService

cmsSlotModelToDataRenderingPopulator

spring file

acceleratorcms/

acceleratorcms-cache-spring.xml

web-content-management-system/

cmsfacades-rendering-cache-spring.xml

flag enable cms.cache.enabled cms.rendering.cache.enabled
properties regioncache.cmsregion.* cms.rendering.region.cache.*

CDN caching

In addition to the caching on the API servers using EhCache regioncmsRenderingCacheRegion, this is highly recommended to review the cache-control headers and use a CDN to cache the CMS endpoints.

Endpoint​ Current​ Suggested​
/cms/pages​ private​ public, 600 sec​
/cms/components​ public, max-age=120​ public, 3600 sec​

 

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Abdul Rahman Aldali
      Abdul Rahman Aldali

      Great article Yannick Robin , Thanks for sharing 👏🏻.

      I have ta question regarding the CDN caching, is there any CDN caching options from SAP or you should be looking for some of 3rd party providers to handle that? I appreciate if you provide some references related to CDN caching.

      Author's profile photo Yannick Robin
      Yannick Robin
      Blog Post Author

      Hello Abdul,

      There is no CDN provided by SAP. Here are some popular 3rd party providers : CloudFlare, Akamai, Edgio, Azure CDN…

      Thanks,

      Yannick

      Author's profile photo Joris QUENEE
      Joris QUENEE

      Wonderful article Yannick Robin

      Regarding CMS personnalisation : https://help.sap.com/docs/SAP_COMMERCE/9d346683b0084da2938be8a285c0c27a/79f3b6c26ba74db19ad30ecd8786fcf4.html?locale=en-US

      This OCC CMS caching seems to be not compatible with. Do you have suggestion to make this feature compatible with internal OCC CMS caching and/or compatible with 3rd party CDN ?

      Author's profile photo Yannick Robin
      Yannick Robin
      Blog Post Author

      This is a good point. I am not sure how to fix but at least I added a section to inform readers about it.

      Maybe the target group should be part of the key when personalization is activated.