Commerce Engine Connect caching

Abstract

How to configure Commerce Engine Connect caching, including Redis caching for distributed deployments and in-memory caching, for development environment.

Commerce Engine (CE) Connect caching stores catalog entities to allow for quicker access from the storefront. The size of Commerce catalogs and the complexity of their structure can affect memory cache behavior.

The Sitecore XC solution supports two Commerce Engine Connect cache providers:

  • Redis - recommended for distributed deployments. By default, Commerce Engine Connect uses Redis.

  • Memory - recommended for single-server deployments.

Commerce Engine Connect distributed caching

In a distributed Commerce deployment, Commerce Engine (CE) Connect uses Redis for caching catalog entities for improving the performance of the Content Delivery (CD) and Content Management (CM) environments. A single instance of Redis can contain cache stores for both CE Connect caching and Commerce Engine caching. The CE Connect cache store uses DB0. The Commerce Engine cache store uses DB1.

Diagram showing Commerce Engine Connect distributed caching in Content Delivery and Content Management environments using Redis.

CE Connect Caching configuration

You can change the CE Connect caching service provider or fine-tune the caching configuration to meet the requirements of your Commerce storefront. The CE Connect Cache settings are located in the c:\inetpub\wwwroot\<site>\App_Config\Include\Y.Commerce.Engine folder, in the Sitecore.Commerce.Engine.Connect.config file.

Note

The Redis cache provider is enabled by default in CE Connect caching configuration. If you enable both Redis and the in-memory cache providers, or if you disable both, CE Connect uses in-memory caching.

//Redis cache provider configuration//
<commerceCachingConfiguration type="Sitecore.Commerce.Engine.Connect.CommerceCachingConfiguration,Sitecore.Commerce.Engine.Connect.Caching">
    <cachingSettings
type="Sitecore.Commerce.Engine.Connect.CachingSettings,
Sitecore.Commerce.Engine.Connect.Caching">
    <redis
type="Sitecore.Commerce.Engine.Connect.RedisCacheSettings,
Sitecore.Commerce.Engine.Connect.Caching"><enabled>true</enabled>
    <cacheStoreName>Commerce-Connector-Redis</cacheStoreName>
    <options
type="Microsoft.Extensions.Caching.Redis.RedisCacheOptions,
Microsoft.Extensions.Caching.Redis">
    <configuration>localhost,defaultDatabase=1,allowAdmin=true</configuration>
    <instanceName>Redis</instanceName>
    </options>
  </redis>
//In-memory cache provider configuration//       
<memory type="Sitecore.Commerce.Engine.Connect.MemoryCacheSettings,
Sitecore.Commerce.Engine.Connect.Caching">
    <enabled>false</enabled>
    <cacheStoreName>Commerce-Connector-Memory</cacheStoreName>
  </memory>
//Cache entry configuration// 
 <cacheEntry
type="Sitecore.Commerce.Engine.Connect.CacheEntrySettings,
Sitecore.Commerce.Engine.Connect.Caching">         
      <cacheName>CommerceConnect</cacheName>
      <expiration>21600000</expiration>
    </cacheEntry>
  /cachingSettings>
</commerceCachingConfiguration>

Cache provider parameters

You can configure the following parameters for your cache provider:

Provider

Parameter

Description

Redis

enabled

Specifies whether the provider is enabled. By default, Redis is enabled (set to true).

cacheStoreName

Sets the name of the cache store.

configuration

Specifies the connection string for the Redis cache provider, for example, localhost (default value).

allowAdmin=True

The allowAdmin=true configuration setting is required to perform flush cache operations.

defaultDatabase

Specifies the default database.

Important

If other applications share the same Redis service, you must specify the defaultDatabase setting, so that CE Connect flush cache operations do not affect other applications.

InstanceName

Sets the Redis instance name.

Memory

enabled

Specifies whether the provider is enabled. By default, the memory case provider is disabled (set to false).

cacheStoreName

Sets the name of the cache store.

evictionPercentage

Sets the threshold at which the cache removes the least recently used entries to make room for new entries. The default value is 0.2.

maxSizeInBytes

Sets the maximum size of the cache store, in bytes. The default value is 9223372036854775807.

code

Sets the maximum time after which the cache store updates its memory statistics. The default value is 2 minutes.

sizeLimit

Sets the maximum size for a cache within the cache store.

expirationScanFrequency

Sets the minimum length of time between scans for expired items.

compactionPercentage

Sets the percentage of cache data to compact when the maximum size is exceeded; the default value is 0.

Cache Entry configuration

You can configure the following parameters for cache entries (for any cache provider):

Parameter

Description

cacheName

Specifies the name of the cache.

expiration

Sets the length of time after which a cache entry expires, in milliseconds. The default is 21600000.

priority

Sets the priority for the cache entry. Possible values are:

  • Low

  • Normal

  • High

  • NeverRemove

absoluteExpirationRelativeToNow

Sets the length of time after which a cache entry expires relative to the current timestamp, in milliseconds.

slidingExpiration

Sets the length of time after which a cache entry expires if it has not been accessed, in milliseconds.

CE Connect Cache maintenance

You can refresh the content of the CE Connect cache in Sitecore Content Editor. (You cannot use the caching API sample requests in Postman to maintain the CE Connect cache.)

To refresh the CE Connect cache:

  1. On the Sitecore Launchpad, click Content Editor.

  2. On the Commerce tab, click Refresh Commerce Cache.

The Refresh Commerce Cache operation refreshes the following caches:

  • Sitecore item cache

  • Content path cache

  • Sitecore data cache

  • Standard value cache

  • Template cache

  • Template engine cache

  • HTML cache

  • Catalog entities

  • Catalog mappings (always cached in memory)