CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
gaurav11
Participant
Introduction

Today, in any traditional e-commerce performance and scalability are essential for delivering outstanding customer experience in the ever-changing world of E-commerce.

Ehcache is one of the very essential elements that may greatly improve the efficiency of any commerce platform. To increase response time and system performance, Ehcache an open source, high performance, distributed caching solution, offers effective data caching and minimize database calls.

Why Does SAP Commerce Need Caching

Huge amount of data, including information about the customer, products, inventories and many more things, are processed by SAP commerce, many of these information are rather static over short time periods in any typical e-commerce environment. It can overload the system and slow down response times to repeatedly access the database for unmodified data by frequently accessing data in memory, caching is essential in resolving this issue, it will be possible to response the future request straight from cache instead of fetching from database, which reduce the burden on the database and enhances the system speed.

Ehcache in SAP Commerce

Easy integration between Ehcache and SAP commerce is possible, its offer a reliable and user-friendly caching functionality that’s aids in the speedup the e-commerce site. Ehcache is made to work with Java application and smooth configuration to meet certain caching needs.

Advantage of Ehcache in SAP commerce

  1. Performance Improvement – Ehcache lowers the response times and improves the overall E-commerce by caching frequently requested information. Better user experience is a direct result of faster reaction times, and successful e-commerce depends on this.


 

  1. Scalability – As E-commerce firm expands, so does the need for scalability and quicker response times. To grow, our caching system horizontally and maintain maximum performance even under heavy loads, Ehcache delivers distributed caching capabilities.


 

  1. Versatile Configuration- Ehcache provide the numbers of configuration options, letting programmers adjust caching behavior to the specific needs of their SAP commerce application. You may set cache expiration times, eviction rules, and other parameters to customize the caching strategy to your business's needs.


 

  1. Minimize Data load - Ehcache stop frequent database request call by storing the data that is unmodified for a brief period of time in memory. This lessens the workload on the database and free up the resource for activities that are more important.


How to configure cache

Below are the steps to populate the master address data on the front end for customer registration, so we have implemented Ehcache as a caching solution.

  1. Create Ehcache configuration file in our custom extension, hybris\bin\custom\custom\customccore\resources\config\ehcache.xml


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false" monitoring="autodetect"


dynamicConfig="true">


<diskStore path="java.io.tmpdir/customcore_cache"/>


<cache name="addressCache"


maxElementsInMemory="100000"


eternal="false"


timeToIdleSeconds="360"


timeToLiveSeconds="360"


overflowToDisk="true"


diskPersistent="false"


maxElementsOnDisk="10"


diskExpiryThreadIntervalSeconds="360"


memoryStoreEvictionPolicy="FIFO"


/></ehcache>




  1. Want to use cache functionally in controller. So, create cache configuration file in our custom OCC extension.


hybris\bin\custom\custom\customocc \resources\occ\v2\customocc\web\spring\cache-config-spring.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:cache="http://www.springframework.org/schema/cache"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:utils="http://www.springframework.org/schema/util"

xsi:schemaLocation="http://www.springframework.org/schema/beans

             http://www.springframework.org/schema/beans/spring-beans.xsd

             http://www.springframework.org/schema/cache

       http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

 

<cache:annotation-driven cache-manager="compositecustomOccCacheManager" key-generator="commerceCacheKeyGenerator"/>

 

<alias name="defaultCompositecustomOccCacheManager" alias="compositecustomOccCacheManager"/>

<bean id="defaultCompositecustomOccCacheManager" class="org.springframework.cache.support.CompositeCacheManager">

<property name="cacheManagers">

<list merge="true">

<ref bean="defaultcustomOccCacheManager"/>

</list>

</property>

</bean>

<alias name="defaultcustomOccCacheManager" alias="customOccCacheManager"/>

<bean id="defaultcustomOccCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">

<property name="cacheManager" ref="customOccEhcache"/>

</bean>

<alias name="defaultcustomOccEhcache" alias="customOccEhcache"/>

<bean id="defaultcustomOccEhcache" class="de.hybris.platform.webservicescommons.cache.TenantAwareEhCacheManagerFactoryBean">

<property name="configLocation" value="classpath:/cache/customocc-ehcache.xml"/>

<property name="cacheNamePrefix" value="customOccCache"/>

</bean>

</beans>

 

  1. Add the @Cacheable annotation. So, that response from JAVA method is cached.


@Cacheable(value = "addressCache", key = "T(de.hybris.platform.commercewebservicescommons.cache.CommerceCacheKeyGenerator).generateKey(true,true,#fields)")

public AddressMasterListWsDTO getAllPrefecture(@RequestParam(defaultValue = DEFAULT_FIELD_SET)final String fields)

 

Please refer the below SAP link for more information on Ehcache Configuration.

https://help.sap.com/docs/SAP_COMMERCE/e5d7cec9064f453b84235dc582b886da/8b711228866910149500b73575cb...
1 Comment