Showing posts with label Ehcache. Show all posts
Showing posts with label Ehcache. Show all posts

How can implement Ehcache in Hybris multi-channel ecommerce suite ? step to implement Ehcache in Hybris

Hybris is provide caching in spilit of content called region and we can configure and add object in each region cache
In Hybris core-cache.xml is heart of caching configuration in Hybris
Suppose we need to implement a another cache region then you need to add below code in core extension spring xml file
<alias alias="cacheRegionsList" name="defaultScenarioCacheRegionList" />
  <bean name="ownProductCacheRegion" class="de.hybris.platform.regioncache.region.impl.EHCacheRegion">
     <constructor-arg name="name" value="ownCacheRegion" />
     <constructor-arg name="maxEntries" value="50000" />
     <constructor-arg name="evictionPolicy" value="LFU" />
     <property name="handledTypes">
         <array>
             <value>1</value>
         </array>
     </property>
  </bean>
 
  <bean id="defaultScenarioCacheRegionList" class="java.util.ArrayList">
                    <constructor-arg>
                        <list>
                             <ref bean="typesystemCacheRegion"/>
                            <ref bean="entityCacheRegion"/>
                            <ref bean="queryCacheRegion"/>
                             <ref bean="ownProductCacheRegion"/>
                        </list>
                    </constructor-arg>
   </bean>
  
  
  
   After add above code you need to access caching by using DefaultCacheController for we need to add below code to access them
  
   @Autowired
 CacheController controller;




 final Collection<CacheRegion> regions = controller.getRegions();
  for (final CacheRegion region : regions)
  {
   if (region.toString().equals("goodyearCacheRegion"))
   {
   
    final Collection<CacheKey> cacheKey = region.getAllKeys();
    for (final CacheKey cach : cacheKey)
    {
     System.out.println(" Cache Region name  " + region.getName() + " Cache key  " + cach.toString());
    
    }
    final CacheStatistics stats = region.getCacheRegionStatistics();
    stats.getHitCount();
    //    (...)
   }
  }