Commerce Engine caching
Sitecore XC solution supports two cache providers:
-
Redis - the Redis cache provider is for use in distributed deployments, including integration, testing, and production environments. By default, Commerce Engine uses Redis caching.
-
Memory - in-memory caching is for use in single-server deployments and development environments only.
Each Commerce Engine service role has a cache store. The cache store contains multiple caches, which are grouped into data cache stores, according to the artifact store ID associated with their environment. Environments that have the same artifact store ID share the same cache data within the cache store, but their cache data is isolated from environments that have different artifact store IDs.
Sitecore XC caching follows an opt-in model, meaning that caching is disabled by default for any commerce entities and non-entities. You must explicitly enable caching for any commerce entities and non-entities that you want to cache through policy configuration.
Distributed caching
For scaled (or distributed, single-server) deployments, you can use the Redis cache provider to host a centralized cache store for the system. Each Commerce Engine service role can access the cache store and retrieve cached data, based on the environment ID specified in the request header.
Memory caching
For single-service deployments, you can use the Memory cache provider to cache commerce items. All Commerce Engine service roles hosted on the machine use the memory cache store to retrieve cached data, based on the environment ID specified in the request header.
Cache provider configuration
The cache provider configuration is stored in the Commerce Engine config.json
file. You must enable one cache provider, and you can only enable one cache provider at a given time. The Redis cache provider is enabled by default.
},
"Caching": {
"Memory": {
"Enabled": false,
"CacheStoreName": "Commerce-Memory-Store"
},
"Redis": {
"Enabled": true,
"CacheStoreName": "Commerce-Redis-Store",
"IntervalBetweenConnectionAttemptsInSeconds": 60,
"RedisConnectionPoolSize": 1,
"RedisCompressionEnabled": true,
"Options": {
"Configuration": "PlaceholderForRedisConfiguration",
"InstanceName": ""PlaceholderForRedisInstanceName"
}
}
The following table lists and describes the configuration parameters for your cache provider:
Cache provider |
Parameter |
Default value |
Description |
---|---|---|---|
Memory |
|
|
Specifies whether the cache provider is enabled (bool.) |
|
|
Sets the name of the cache store. | |
|
|
Sets the threshold at which the cache removes the least recently used entries to make room for new entries. | |
|
|
Sets the maximum size in bytes permitted in the cache store. | |
|
|
Sets the maximum time in seconds after which the cache store updates its memory statistics. | |
|
|
Sets the maximum number of items for a cache store. If no value is specified, limitation is based on maximum size allowed in cache (as determined by the | |
|
|
Sets the minimum length of time (in seconds) between scans for expired items. | |
|
|
Sets the percentage, expressed as a decimal, of cache data to compact when the maximum size is exceeded. | |
Redis |
|
|
Specifies whether the Redis cache provider is enabled (bool.). |
|
|
Sets the name of the cache store. | |
|
|
Sets the number of seconds before a failed connection attempts to connect again. | |
|
|
Specifies the number of connections that can be created in the connection pool. | |
|
|
Specifies whether to compress cached data. | |
|
|
Specifies the connection string for the Redis cache provider. Note You can append additional Redis configuration options to the connection string to meet specific deployment requirements. | |
|
|
Sets the Redis instance name. |
Entity caching configuration
The Commerce Core plugin provides the policies that govern entity caching for the Commerce Engine.
The EntityCachingPolicy
policy defined by the Commerce Core plugin controls caching behavior for commerce entities. You can configure an entity caching policy for each entity that you want to cache. The following shows an example of the EntityCachingPolicy for that defines caching configuration for entity Sitecore.Commerce.Plugin.Content.ContentPath
:
{
"$type": "Sitecore.Commerce.Core.EntityCachingPolicy, Sitecore.Commerce.Core",
"EntityFullName": "Sitecore.Commerce.Plugin.Content.ContentPath",
"AllowCaching": true,
"Priority": "Normal",
"Expiration": 86400000,
"HasNegativeCaching": true,
"CacheName": "ContentPaths",
"EntityIdPrefix": "Entity-ContentPath"
}
The following table describes the parameters in the entity caching policy configuration:
Parameter |
Default value |
Description |
---|---|---|
|
|
Sets the full name of the entity type to be cached. |
|
|
Enables or disables (bool.) caching for the entity. |
|
|
Sets the priority for the cache entry. Possible values are:
|
|
|
Sets the length of time after which a cache entry expires, in milliseconds. |
|
|
Sets the length of time after which a cache entry expires relative to the current timestamp, in milliseconds. |
|
|
Sets the length of time after which a cache entry expires if it has not been accessed, in milliseconds. |
|
|
Enables or disables (bool.) negative caching for the entity type. When set to true, it caches the fact that the entity does not exist, which prevents repeated calls to the SQL Server for entities that have been previously requested, and do not exist. |
|
Sets the name of the cache for this entity type. | |
|
The prefix to identify the entity type. |
Caching policy set
The Sitecore XC solution includes a caching policy set file that contains system caching configuration. All default environments included with the Sitecore XC solution (for example, Habitat) reference the default caching policy set.
The Plugin.Caching.PolicySet-1.0.0.json
file is stored in the wwwroot\data\Environments folder and contains caching policies for commerce entities and non-entities.
The caching policy set contains policy configuration for the following commerce entity caches:
-
Content paths cache
-
Content items cache
-
Shops cache
-
Policy Sets cache
-
Entity Indexes cache
-
Promotions cache
-
Promotion Books cache
-
Catalogs cache
-
Categories cache
-
Relationship Definitions cache
-
Sellable Items cache
-
Inventory Sets cache
-
Price Cards cache
-
Price Books cache
-
Localization Entities cache
-
Versioning Entities cache
-
Workflows cache
-
Search Statuses cache
In addition, the Caching policy set contains caching policy configuration for the following non-entity items:
-
Management cache (caches item model objects from the Commerce Control Panel)
-
Custom Relationships cache (caches a list of custom relationships)
-
Associated/Disassociated Catalogs cache (caches a list of associated and disassociated catalogs for each promotion book)
-
Localized Terms cache (caches a list of commerce localized terms)
-
Customer Statuses cache (caches a list of localized customer statuses)
-
Returns cache policy (caches a list of localized reasons-for-returns)
Caching API commands
You administer caching through the CommerceOps API. You can use the Postman samples (located in the SitecoreCommerce_DevOps collection) to execute the caching commands.
The following table lists the API commands for caching:
Command |
Description |
---|---|
|
Retrieves all the cache stores in the system. |
|
Retrieves a named cache store. |
|
Retrieves the caches within the cache store that match the environment's artifact store ID. |
|
Retrieves a named cache. If the cache is not present in the cache store, the system returns a 404 error. |
|
Clears all the caches within the cache store. This command is not supported for the Redis cache provider. You must clear the cache store directly in Redis. |
|
Clears all caches in the data store. The Commerce Engine determines the data store from the environment name specified in the request header. This command is not supported for the Redis cache provider. You must clear the data store directly in Redis. |
|
Clears the named cache within a cache store. This command is not supported for the Redis cache provider. You must clear the cache directly in Redis. |