views:

1559

answers:

2

I'm trying to use declarative caching from the Spring Modules project.

It's not working ie. nothing appears to be getting cached.

Here's my configuration:

<bean id="cacheManager"
  class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
</bean>

<bean id="cacheProviderFacade"
  class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
  <property name="cacheManager" ref="cacheManager" />
</bean>

<bean id="cacheableService"
 class="org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean">
 <property name="cacheProviderFacade" ref="cacheProviderFacade" />
 <property name="cachingModels">
  <props>
   <prop key="get*">cacheName=default</prop>
  </props>
 </property>
 <property name="flushingModels">
  <props>
   <prop key="update*">cacheNames=default</prop>
  </props>
 </property>
 <property name="target" ref="myServiceBean" />
</bean>

And then, here's the logging from when Spring loads up the application context...

24 Feb 2009 14:26:20,785 INFO    org.springframework.cache.ehcache.EhCacheManagerFactoryBean - Initializing EHCache CacheManager
24 Feb 2009 14:26:20,801 DEBUG net.sf.ehcache.CacheManager - Configuring ehcache from classpath.
24 Feb 2009 14:26:20,801 WARN  net.sf.ehcache.config.ConfigurationFactory - No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: zip:C:/bea/weblogic81/server/bin/myserver/.wlnotdelete/extract/myserver_threeoneoneonline_threeoneoneonline/jarfiles/WEB-INF/lib/ehcache-1.3.0.jar!/ehcache-failsafe.xml
24 Feb 2009 14:26:20,801 DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from URL: zip:C:/bea/weblogic81/server/bin/myserver/.wlnotdelete/extract/myserver_threeoneoneonline_threeoneoneonline/jarfiles/WEB-INF/lib/ehcache-1.3.0.jar!/ehcache-failsafe.xml
24 Feb 2009 14:26:20,801 DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from InputStream
24 Feb 2009 14:26:20,816 DEBUG net.sf.ehcache.config.DiskStoreConfiguration - Disk Store Path: C:\DOCUME~1\bpapa\LOCALS~1\Temp\
24 Feb 2009 14:26:20,832 DEBUG net.sf.ehcache.config.ConfigurationHelper - No CacheManagerEventListenerFactory class specified. Skipping...
24 Feb 2009 14:26:20,832 DEBUG net.sf.ehcache.config.ConfigurationHelper - No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener.
24 Feb 2009 14:26:20,847 DEBUG net.sf.ehcache.config.ConfigurationHelper - No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider.
24 Feb 2009 14:26:20,863 DEBUG net.sf.ehcache.config.ConfigurationHelper - No BootstrapCacheLoaderFactory class specified. Skipping...

After this, I hit a page that calls a method prefixed with "get" from the "myServiceBean" bean. But, nothing is logged that any caching is going on. I've turned logging all the way up to debug for springmodules, spring's cache package, and DEBUG... since Spring Modules examples are pretty few and far between on the web, I was wondering if anybody has seen this before...

+2  A: 

You should create an ehcache.xml file for your config since I don't believe the fail safe cache works with declarative caching. We set up our caching using the ehcache Spring modules XML schema and annotations. If using an explicit ehcache.xml does not solve your issue, then I can dig up some code that does it (close to) your way.

Patrick
thanks, I'll try that and post an update...
bpapa
how about an update bpapa? thanks!
Dan
I never tried it, sorry! Wound up moving on to another project.
bpapa
A: 

I am one of the authors of a new project intended to provide Ehcache integration for Spring 3 projects via annotations:

http://code.google.com/p/ehcache-spring-annotations/

The library provides two method-level annotations in the spirit of Spring’s @Transactional:

@Cacheable @TriggersRemove

When appropriately configured in your Spring application, this project will create caching aspects at runtime around your @Cacheable annotated methods.

Usage documentation can be found on the project wiki

Eric