Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Is it possible to make Spring work with Ehcache? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to make Spring work with Ehcache?

    Hello,
    I'm trying to configure Ehcache with Spring using referehce from springmodules.dev.java.

    And have one problem - cache does not work

    My configuration is:
    Code:
            <bean id="cacheProviderFacade" class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
                <property name="cacheManager" ref="cacheManager" />
            </bean>
            <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
                <property name="configLocation" value="classpath:ehcache.xml"/>
            </bean>
        <bean id="cacheableService" class="org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean">
            <property name="cacheProviderFacade" ref="cacheProviderFacade" />
            <property name="cachingModels">
                <map>
                    <entry key="find*">
                        <bean class="org.springmodules.cache.provider.ehcache.EhCacheCachingModel">
                            <property name="cacheName" value="testCache" />
                        </bean>
                    </entry>
                </map>
            </property>
            <property name="target" ref="localeSearchDao"/>
        </bean>
    In the log file I see:

    Code:
    2009-03-30 17:01:13,047 [DEBUG] net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from InputStream
    2009-03-30 17:01:13,067 [DEBUG] net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xmlns:xsi
    2009-03-30 17:01:13,067 [DEBUG] net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
    2009-03-30 17:01:13,077 [DEBUG] net.sf.ehcache.CacheManager - No disk store path defined. Skipping disk store path conflict test.
    2009-03-30 17:01:13,077 [DEBUG] net.sf.ehcache.config.ConfigurationHelper - No CacheManagerEventListenerFactory class specified. Skipping...
    2009-03-30 17:01:13,077 [DEBUG] net.sf.ehcache.config.ConfigurationHelper - No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener.
    2009-03-30 17:01:13,077 [DEBUG] net.sf.ehcache.config.ConfigurationHelper - No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider.
    2009-03-30 17:01:13,207 [DEBUG] net.sf.ehcache.config.ConfigurationHelper - No BootstrapCacheLoaderFactory class specified. Skipping...
    2009-03-30 17:01:13,207 [DEBUG] net.sf.ehcache.config.ConfigurationHelper - No BootstrapCacheLoaderFactory class specified. Skipping...
    2009-03-30 17:01:13,217 [DEBUG] net.sf.ehcache.store.MemoryStore - Initialized net.sf.ehcache.store.LruMemoryStore for testCache
    2009-03-30 17:01:13,217 [DEBUG] net.sf.ehcache.store.LruMemoryStore - testCache Cache: Using SpoolingLinkedHashMap implementation
    2009-03-30 17:01:13,217 [DEBUG] net.sf.ehcache.Cache - Initialised cache: testCache
    I turned log level to "Debug" for for "org.springmodules" as well, but got no log records.

    So, now I get nothing from cache - everything comes from DB.
    I would very appreciate if someone could tell me what I do wrong.

    Thanks in advance.

  • #2
    Solution

    If someone is intrested in this topic, I found out the solution. I was able to configure ehcahce for using it with annotations. Actually, it's much more convenient than configure all cases in spring descriptor.

    ehcache.xml: (in classpath)
    Code:
    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
        <cacheManagerEventListenerFactory class="" properties="" />
        <defaultCache
                maxElementsInMemory="10000"
                eternal="false"
                timeToIdleSeconds="120"
                timeToLiveSeconds="120"
                overflowToDisk="true"
                diskSpoolBufferSizeMB="30"
                maxElementsOnDisk="10000000"
                diskPersistent="false"
                diskExpiryThreadIntervalSeconds="120"
                memoryStoreEvictionPolicy="LRU"
                />
    
        <cache name="testCache"
                maxElementsInMemory="10000"
                eternal="false"
                timeToLiveSeconds="1200"
                overflowToDisk="false"
                diskPersistent="false"
                diskExpiryThreadIntervalSeconds="120"
                memoryStoreEvictionPolicy="LRU"/>
    </ehcache>
    Spring configuration:

    Code:
        <bean id="cacheProviderFacade" class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
            <property name="cacheManager" ref="cacheManager" />
        </bean>
        <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:ehcache.xml"/>
        </bean>
    
        <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
        
        <bean id="cachingInterceptor" class="org.springmodules.cache.interceptor.caching.MetadataCachingInterceptor">
            <property name="cacheProviderFacade" ref="cacheProviderFacade" />
            <property name="cachingAttributeSource" ref="cachingAttributeSource" />
            <property name="cachingModels">
                <props>
                    <prop key="customizedCacheName">cacheName=testCache</prop>
                </props>
            </property>
        </bean>
        <bean id="cachingAttributeSourceAdvisor" class="org.springmodules.cache.interceptor.caching.CachingAttributeSourceAdvisor">
            <constructor-arg ref="cachingInterceptor" />
        </bean>
        <bean id="cachingAttributeSource" class="org.springmodules.cache.annotations.AnnotationCachingAttributeSource"/>
    Usage in code:
    Code:
    import org.springmodules.cache.annotations.Cacheable;
    
    ........................................................................
    
        @Cacheable(modelId = "customizedCacheName")
        List<ComboboxTransfer> findAllCountries();
    Last edited by vlakon; Mar 31st, 2009, 07:38 AM.

    Comment

    Working...
    X