Author |
Message |
06/25/2012 11:40:28
|
giandrea
neo
Joined: 06/25/2012 11:39:11
Messages: 5
Offline
|
I'm trying to use Sping Annotation cache with EhCache. So, for first, I added the dependency to my pom.xml and configured the application-context.xml as:
Code:
<ehcache:annotation-driven cache-manager="cacheManager" />
<ehcache:config cache-manager="cacheManager">
<ehcache:evict-expired-elements interval="60" />
</ehcache:config>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="ehcache.xml"/>
</bean>
This is the ehcache.xml configuration file:
<?xml version="1.0" encoding="UTF-8"?>
Code:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
<cache name="alfresco" maxElementsInMemory="10" eternal="true" overflowToDisk="false" />
</ehcache>
for last, I added the Annontation @Cachable to the methods that need to be cached:
@Cacheable(value="alfresco")
public EMContents getContents(RestTemplate restTemplate, String ticket, String webScriptUrl, String em_name)
At this point, when I start the web application, it seems to work fine, but I get this error message:
Code:
25 Jun 2012 19:40:07 INFO EhCacheManagerFactoryBean:100 - Initializing EHCache CacheManager
25 Jun 2012 19:40:07 DEBUG ConfigurationFactory:148 - Configuring ehcache from InputStream
25 Jun 2012 19:40:07 DEBUG BeanHandler:271 - Ignoring ehcache attribute xmlns:xsi
25 Jun 2012 19:40:07 DEBUG BeanHandler:271 - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
25 Jun 2012 19:40:07 DEBUG PropertyUtil:88 - propertiesString is null.
25 Jun 2012 19:40:07 DEBUG CacheManager:605 - No disk store path defined. Skipping disk store path conflict test.
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:184 - No CacheManagerEventListenerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:1183 - Initialised cache: alfresco_action
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:331 - CacheDecoratorFactory not configured. Skipping for 'alfresco_action'.
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:360 - CacheDecoratorFactory not configured for defaultCache. Skipping for 'alfresco_action'.
25 Jun 2012 19:40:07 DEBUG Cache:1183 - Initialised cache: alfresco
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:331 - CacheDecoratorFactory not configured. Skipping for 'alfresco'.
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:360 - CacheDecoratorFactory not configured for defaultCache. Skipping for 'alfresco'.
25 Jun 2012 19:40:07 DEBUG DefaultListableBeanFactory:458 - Finished creating instance of bean 'cacheManager'
Any clue? Something seems to be wrong with my configuration.
Thanks for your time<br />Andrea
|
|
|
06/25/2012 15:45:42
|
grenfro
neo
Joined: 06/25/2012 09:35:52
Messages: 8
Offline
|
Hello giandrea,
These messages are at debug level and thus are not errors. Basically they are saying that you have not enabled certain features that EhCache offers.
--Glenn
|
|
|
06/26/2012 02:14:23
|
giandrea
neo
Joined: 06/25/2012 11:39:11
Messages: 5
Offline
|
Hi Glenn,
thanks for your reply. My point is, how can I enable the caching? It's not working and I don't understand if it's something misconfigured.
Thanks,
Andrea
|
|
|
06/26/2012 03:52:49
|
steve
ophanim
Joined: 05/24/2006 14:22:53
Messages: 619
Offline
|
I'll let someone who knows spring annotations help you get through the issues of configuring it but I thought I would point out that instead of using count based tuning (save the last 10 or 100 method invocations) you'd probably get better performance if you used bytes based tuning (use 100m of heap for caching).
http://terracotta.org/products/enterprise-ehcache/automatic-resource-control
http://ehcache.org/documentation/configuration/cache-size
|
Want to post to this forum? Join the Terracotta Community |
|
|
06/26/2012 04:52:09
|
giandrea
neo
Joined: 06/25/2012 11:39:11
Messages: 5
Offline
|
Thanks,
the problem is that I'm expecting something like that in my log:
DEBUG [com.googlecode.ehcache.annotations.interceptor.EhCacheInterceptor]: Generated key '167334053963' for invocation: ReflectiveMethodInvocation: public abstract java.util.Collection com.goyello.esa.storage.MessageStorage.findAllMessages(); target is of class [com.goyello.esa.storage.MemoryMessageStorage] DEBUG [com.goyello.esa.storage.MemoryMessageStorage]: == got all messages, size=5
but, my annotated method it's called every time. Cache is not working....
|
|
|
06/26/2012 05:38:40
|
edalquis
journeyman
Joined: 02/10/2010 10:44:27
Messages: 11
Offline
|
Hello, one of the authors of the annotations package here. A few questions:
For your method:
@Cacheable(value="alfresco")
public EMContents getContents(RestTemplate restTemplate, String ticket, String webScriptUrl, String em_name)
1. Is this method defined by an interface
2. If yes for 1 are you calling the method via that interface from other spring beans
3. You probably don't want the restTemplate being used as part of the cache key. Take a look at http://ehcache-spring-annotations.googlecode.com/svn/site/current/apidocs/com/googlecode/ehcache/annotations/PartialCacheKey.html
You can annotate the three string parameters with @PartialCacheKey so that the RestTemplate parameter is ignored for key generation.
|
|
|
06/26/2012 05:47:49
|
giandrea
neo
Joined: 06/25/2012 11:39:11
Messages: 5
Offline
|
Hi,
1) no, it's not an interface
2) I changed the method to
@Cacheable(value="alfresco")
public EMContents getContents(String em_name)
but still not working. From junit class I'm calling this method five times but it's not caching anything...
|
|
|
06/26/2012 06:05:29
|
edalquis
journeyman
Joined: 02/10/2010 10:44:27
Messages: 11
Offline
|
Your method needs to be defined by an interface and clients all must use the interface to make the call. The library uses spring's dynamic proxy support which creates a wrapper around the annotated bean that implements all of the interfaces the bean implements. That wrapper is then what is injected into dependent beans.
|
|
|
06/26/2012 06:16:37
|
giandrea
neo
Joined: 06/25/2012 11:39:11
Messages: 5
Offline
|
I read on a blog that Annotation has to be added to the method implementation of the interface, is it correct?
Is there another way to use Spring annotation cache without use interface?
|
|
|
06/26/2012 06:24:46
|
edalquis
journeyman
Joined: 02/10/2010 10:44:27
Messages: 11
Offline
|
The annotation can go on either the interface or the concrete class. Once the JSR107 annotations are final there will be support for Spring's CGLIB class rewriting proxy support which doesn't require an interface but until then an interface is required (and recommended for pretty much every spring annotation that results in a proxy)
|
|
|
05/23/2014 15:38:59
|
shisan
neo
Joined: 05/23/2014 15:36:28
Messages: 2
Offline
|
Hi giandrea ,
I am also facing same problem that you had.
Are you able to solve the problem ?
If you , can you please tell me how you solve the problem.
Thanks a lot
Shibaji
|
|
|
05/23/2014 15:38:59
|
shisan
neo
Joined: 05/23/2014 15:36:28
Messages: 2
Offline
|
Hi giandrea ,
I am also facing same problem that you had.
Are you able to solve the problem ?
If you , can you please tell me how you solve the problem.
Thanks a lot
Shibaji
|
|
|
|