We want to take advantage of the ehcache library used in the dxa project for our custom methods other than the existing dd4t object caching. I modified the configuration as per Spring Caching Example + EhCache. However my custom method gets executed on every refresh and does not return the cached object as the example stated. I can see the following logs in the ehcache-logfile.
CacheManager - CacheManager already shutdown ConfigurationFactory - Configuring ehcache from ehcache.xml found in the classpath: file:/D:/apache/tomcat-sh-staging-web1/webapps/ROOT/WEB-INF/classes/ehcache.xml MemoryStore - Initialized net.sf.ehcache.store.MemoryStore for customBrandListCache ExtendedStatisticsImpl - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE ExtendedStatisticsImpl - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE_BYTES Cache - Initialised cache: customBrandListCache ConfigurationHelper - CacheDecoratorFactory not configured. Skipping for 'customBrandListCache'. ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'customBrandListCache'. CacheManager - Attempting to create an existing singleton. Existing singleton returned.
ehcache.xml
<cache name="DD4T-Objects"
eternal="false"
maxEntriesLocalHeap="10000"
timeToLiveSeconds="3600"
timeToIdleSeconds="60"
memoryStoreEvictionPolicy="LRU">
</cache>
<cache name="DD4T-Dependencies"
maxEntriesLocalHeap="50000"
memoryStoreEvictionPolicy="LRU">
</cache>
<cache name="customBrandListCache"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="0" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LRU"
transactionalMode="off">
<!--<persistence strategy="none" />-->
</cache>
spring-context.xml
<context:annotation-config/>
<context:component-scan base-package="com.sdl.webapp, com.sdl.dxa, com.khayal.shero"/>
<!-- DD4T Cache Provider -->
<bean id="cacheProvider" class="org.dd4t.core.providers.EHCacheProvider">
<property name="checkForPreview" value="true"/>
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" p:shared="true"/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcache"/>
<!-- Uncomment this if you want to disable the cache in DD4T -->
<!-- bean id="cacheProvider" class="org.dd4t.providers.impl.NoCacheProvider"/ -->
<!-- Enables caching through annotations -->
<cache:annotation-driven key-generator="enhancedDefaultKeyGenerator"/>
<bean id ="enhancedDefaultKeyGenerator" class="com.sdl.dxa.EnhancedDefaultKeyGenerator"/>
Method
@Cacheable(value="customBrandListCache", key="#entityId")
public BrandList getCachedCustomBrandList(Entity objEntity, int entityId, String brandListType, CommonRequestServices commonRequestServices, String searchText) {
long startTime = System.currentTimeMillis(), endTime;
LOG.error(" Entered getCachedCustomBrandList ");
//String methodParams = "[Entity Id: " + objEntity.getId() + "
...
return objBrandList;
}
Calling class
CacheMethods cacheMethod = new CacheMethods(request);
entity = (Entity) cacheMethod.getCachedCustomBrandList(entity,Integer.parseInt(entity.getId()), BrandSearchService.BRANDLISTTYPE_TOP_BRANDS, commonRequestServices, "");
But the logs show that the code is implemented everytime. Can anyone help me? Is something wrong with the configuration? I am not getting any more logs than the one listed above. Nothing gets generated on refreshing the page.