Skip to Content
0
Former Member
Nov 05, 2018 at 05:56 PM

Does @Cachable work in Hybris?

1363 Views

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"/>
 </utils:list>

 <alias name="defaultCompositeWhrCoreCacheManager" alias="compositeWhrCoreCacheManager"/>
 <bean id="defaultCompositeWhrCoreCacheManager" class="org.springframework.cache.support.CompositeCacheManager">
     <property name="cacheManagers">
         <ref bean="whrCoreCacheManagerList"/>
     </property>
 </bean>

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

 <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"/>
 </bean>

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

 <cache:advice></<cache:advice>

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?