Written by The Jahia Team
   Estimated reading time:

Why caching?

Caching is used throughout the system to guarantee quick access to information and reduce the load on the system. All catalog entries are cached and can be accessed without making calls to Elasticsearch after initial calls are made.

There two types of data that are cached in Commerce I/O:  catalog (product and category) and user data.

Catalog cache configuration

You can find the classes used for product and category caching in the package.

The main class containing cache configuration is StoreCacheManager. The createStoreCache method creates the cache and sets the expiration time to 3,600 seconds. From that point on every request for a product or category in the StoreDataSource class is cached. The cache is invalidated in the indexCatalogAndProduct method of the CatalogIndexerImpl class on every successful index operation.

To be able to work with internationalized data, the external provider information for every international property is included in cache as valuesForLazyProperties map in the model class. These values are resolved at run time in the geti18nPropertyValues method of StoreDataSource.  If the product or category is already cached in some language and you try to access it in a language that do not have a map entry, Elasticsearch will be queried again.

User cache configuration

You can find the class used for user caching in the Commerce IO SAP Hybris Customer Provider module.

The cache is created inside createHybrisCache method with an expiration time of 90,000 seconds. That expiration time is the default expiration time for a Hybris token.

The cache is used in the HybrisUsersGroupsProvider class.

Checking cache

The cache can be explored in tools.

Navigate to <your host>/modules/tools/index.jsp and then click on Cache management. You will see 4 caches that belong to Commerce I/O: HybrisGroupsCache, HybrisUsersCache, StoreCatalogCache and StoreProductCache.  

HybrisUserCache uses userId as a key while HybrisGroupsCache is not yet used but can be utilized to enhance caching features.  

StoreProductCache keys contain information about the environment, specifically the Elasticsearch connection name and index prefix separated by an underscore, and product codes and has the following structure: <connection name>_<prefix>p<product code>.

StoreCategoryCache uses similar key structure as above with minor exceptions. Product code is replaced by category path, p is replaced by c and _categories_ is added:

<connection name>_<prefix>_categories_c<category path>