Ehcache with Spring with CacheDecoratorFactory not configured
Asked Answered
S

2

6

I am implementing ehcache with Spring project but not success.

Here is my setting in applicationContext.xml:

<ehcache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="/META-INF/spring/ehcache.xml" />
</bean>

Here is my setting in ehcache.xml:

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

    <diskStore path="java.io.tmpdir" /> 
    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
    <cache name="listTop" maxElementsInMemory="10" eternal="true" overflowToDisk="false" />

</ehcache>

Here is my implementation class:

@Cacheable(cacheName="listTop")
public void listTop(News news, String regionCode, Integer count, Integer categoryId, String listType){
//code here//
}

I got the following message that seems the cache is not configured:

1827 DEBUG net.sf.ehcache.config.BeanHandler  - Ignoring ehcache attribute xmlns:xsi
1827 DEBUG net.sf.ehcache.config.BeanHandler  - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
1828 DEBUG net.sf.ehcache.config.DiskStoreConfiguration  - Disk Store Path: C:\Users\TOMMY~1.LOC\AppData\Local\Temp\
1847 DEBUG net.sf.ehcache.util.PropertyUtil  - propertiesString is null.
1860 DEBUG net.sf.ehcache.config.ConfigurationHelper  - No CacheManagerEventListenerFactory class specified. Skipping...
1918 DEBUG net.sf.ehcache.Cache  - No BootstrapCacheLoaderFactory class specified. Skipping...
1918 DEBUG net.sf.ehcache.Cache  - CacheWriter factory not configured. Skipping...
1918 DEBUG net.sf.ehcache.config.ConfigurationHelper  - No CacheExceptionHandlerFactory class specified. Skipping...
1932 DEBUG net.sf.ehcache.Cache  - No BootstrapCacheLoaderFactory class specified. Skipping...
1932 DEBUG net.sf.ehcache.Cache  - CacheWriter factory not configured. Skipping...
1932 DEBUG net.sf.ehcache.config.ConfigurationHelper  - No CacheExceptionHandlerFactory class specified. Skipping...
1954 DEBUG net.sf.ehcache.store.MemoryStore  - Initialized net.sf.ehcache.store.MemoryStore for listTop
1991 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE
1993 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE_BYTES
1994 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Pass-Through Statistic: LOCAL_DISK_SIZE
1994 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Pass-Through Statistic: LOCAL_DISK_SIZE_BYTES
1994 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Pass-Through Statistic: WRITER_QUEUE_LENGTH
1994 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Pass-Through Statistic: REMOTE_SIZE
1995 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Pass-Through Statistic: LAST_REJOIN_TIMESTAMP
2012 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: OFFHEAP_GET
2013 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: OFFHEAP_PUT
2014 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: OFFHEAP_REMOVE
2014 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: DISK_GET
2014 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: DISK_PUT
2015 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: DISK_REMOVE
2015 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: XA_COMMIT
2015 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: XA_ROLLBACK
2016 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: XA_RECOVERY
2017 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: CLUSTER_EVENT
2017 DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl  - Mocking Operation Statistic: NONSTOP
2024 DEBUG net.sf.ehcache.Cache  - Initialised cache: listTop
2024 DEBUG net.sf.ehcache.config.ConfigurationHelper  - CacheDecoratorFactory not configured. Skipping for 'listTop'.
2024 DEBUG net.sf.ehcache.config.ConfigurationHelper  - CacheDecoratorFactory not configured for defaultCache. Skipping for 'listTop'.

Is there anyone know and help? Many thanks.

Stollings answered 9/10, 2013 at 2:56 Comment(0)
U
4

You need to tell EhCache to apply the decorator to the defined cache like this (and you have to implement MyCacheDecoratorFactory to do what you want):

<cache name="listTop" maxElementsInMemory="10" eternal="true" overflowToDisk="false" ><cacheDecoratorFactory class="com.test.MyCacheDecoratorFactory", properties="blah=true,someValue=2000" /></cache>
Upstage answered 12/5, 2014 at 13:22 Comment(1)
I missed the fact that you can pass properties - thanksMalo
Z
3

Cache not working has nothing to do with CacheDecoratorFactory. These are debug logs telling you that you're not using a CacheDecoratorFactory.

CacheDecorator are a way for the developer to add functionalities to the cache. More on Ehcache 2.8 documentation.

Note that the CacheDecoratorFactory class disappeared in 3.0

Zymase answered 22/5, 2019 at 8:25 Comment(1)
Thank you for the clarification. When I have started use ehcache in PlayFramework, I was getting this message, Trying to decide this is ignorable or not. Now I will just ignore it.Crossarm

© 2022 - 2024 — McMap. All rights reserved.