Caching

October 8, 2024

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.

Two types of data are cached in Commerce IO:  catalog (product and category) and user data.

Catalog cache configuration

You can find the classes used for product and category caching in the org.jahia.modules.commerce.io.edp.datasource.cache 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 the 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 one language and you try to access it in a language that does 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 the cache

You can explore the cache in tools by navigating to <your host>/modules/tools/index.jsp and clicking 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.
  • HybrisGroupsCache is not used by the system 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 structures 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>