Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Loading...
Applies to versions: 14 and higher
Other versions:
ARCHIVED This content is retired and no longer maintained. See the version selector for other versions of this topic.

Caching

Recommended reading 
Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.

This topic describes Commerce-specific caching and examples of how Optimizely Commerce uses caching for its product catalogs and their entries. Platform cache functionality, including remote synchronization, is part of the Optimizely platform.  

Classes in this topic are in the Mediachase.Commerce.Catalog namespace.

Subsystem caching

Caching options for each subsystem, such as catalogs and orders, can be configured using either AppSettings.json or the ConfigureServices method of the Startup class.

Example: Cache settings for the Catalogs subsystem, using AppSettings.json.

"EPiServer": {
   "Commerce": {
      "CatalogOptions": {
        "Cache": {
          "UseCache": true,
          "ContentVersionCacheExpiration": "00:05:00",
          "CollectionCacheExpiration": "00:05:00",
          "EntryCacheExpiration": "00:05:00",
          "NodeCacheExpiration": "00:05:00"
        }
      }
   }
}

Example: Cache settings for the Catalogs subsystem, using Startup.

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<CatalogOptions>(o =>
    {
        o.Cache.UseCache = true;
        o.Cache.ContentVersionCacheExpiration = TimeSpan.FromMinutes(05);
        o.Cache.CollectionCacheExpiration = TimeSpan.FromMinutes(05);
        o.Cache.EntryCacheExpiration = TimeSpan.FromMinutes(05);
        o.Cache.NodeCacheExpiration = TimeSpan.FromMinutes(05);
    });
}

The CollectionCacheExpiration responds to an entry array, and "entry" responds to a single entry. What is actually cached is the CatalogEntryDto and, because the Entry object is created from the Data Transfer Object (DTO), you cache the DTO. In some cases, you can also cache the entry objects themselves rather than the DTO.

Cache invalidation

In the Catalogs subsystem example, the cache is invalidated if it reaches the cache timeout specified above (00:05:00) for the request type, or if an object is updated. You can also invalidate cache for the entire catalog by calling CatalogCache.Clear().

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 02, 2021

Recommended reading