Showing results for 
Search instead for 
Did you mean: 

Does @Cachable work in Hybris?

Former Member
0 Kudos

Hi to all. I have tried to add @org.springframework.cache.annotation.Cacheable in core extension for method something like this

 public class SomeClass implementes SomeInterface {
     @Cacheable(value = "plantsCache", key = "T(org.springframework.cache.interceptor.SimpleKeyGenerator).generateKey(#baseStore.uid)")
         public SomeData getSomeData(@Nonnull final BaseStoreModel baseStore) {

And spring configuration:

 <cache:annotation-driven cache-manager="compositeWhrCoreCacheManager"/>

 <utils:list id="defaultWhrCoreCacheManagerList">
     <ref bean="whrCoreCacheManager"/>

 <alias name="defaultCompositeWhrCoreCacheManager" alias="compositeWhrCoreCacheManager"/>
 <bean id="defaultCompositeWhrCoreCacheManager" class="">
     <property name="cacheManagers">
         <ref bean="whrCoreCacheManagerList"/>

 <alias name="defaultWhrCoreCacheManager" alias="whrCoreCacheManager"/>
 <bean id="defaultWhrCoreCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
     <property name="cacheManager" ref="whrCoreEhcache"/>

 <alias name="defaultWhrCoreEhcache" alias="whrCoreEhcache"/>
 <bean id="defaultWhrCoreEhcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
     <property name="configLocation" value="/mycore/cache/ehcache.xml"/>
     <property name="cacheManagerName" value="whrCoreCache"/>

In some class

 private SomeInterface instanceFromSpringContext;

When instanceFromSpringContext.getSomeData(baseStore) is called again then the real call still is executed, and what is interesting the bean is not proxied. The instance still directly has an implementation of SomeClass. Also, I have tried not annotation based mechanism when


elements are configured, but the issue is still the same, looks like the root is somewhere in another place. Does anyone have experience of adding @Cachable for methods of classes which implement interfaces?

View Entire Topic
Former Member
0 Kudos

Thanks . The issue was resolved, maybe it will be interested:

Bean A has methods with annotation @Cachable. Bean B a has dependency on Bean A and also Bean B implements org.springframework.beans.factory.FactoryBean and Spring inits Bean B before enabling caching(when proxies are created for beans which methods have annotation @Cacheable).

Santa Barbara 🙂

I'm interesting is it Spring issue?

0 Kudos

We only had a simple implementation of an interface where we used cachable :)