Announcement Announcement Module
Collapse
No announcement yet.
@Cacheable not working for a method call Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Cacheable not working for a method call

    Good morning,

    I am working on a little RSS feed for a site that is updated 1 or 2 times a day. I am looking to use the @Cacheable annotation to tell my service to cache the result of a call that returns a list of items, but it seems as if the results of the method I am looking to cache are not actually being cached.

    I am using Spring 3.1.0.M2 along with Ehcache 2.4.4. Below are some of the snippets of my configuration and code.

    I can confirm that the annotation is being picked up by putting in a breakpoint into the SpringCachingAnnotationParser, but again it is never being invoked by the CacheInterceptor. Any help with this would be much appreciated.

    My controller is making a call to the StadiumReviewService as such:
    Code:
    List<StadiumReview> reviewItems = new ArrayList<StadiumReview>();
    		if(league != null) {
    			reviewItems = stadiumReviewService.getReviews(league);
    }
    Code:
    <properties>
    		<java-version>1.6</java-version>
    		<org.springframework-version>3.1.0.M2</org.springframework-version>
    		<ehcache.version>2.4.4</ehcache.version>
    		<org.aspectj-version>1.6.9</org.aspectj-version>
    		<org.slf4j-version>1.5.10</org.slf4j-version>
    		<logback-version>0.9.18</logback-version>
    	</properties>
    	<dependencies>
    		<!-- Spring -->
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>${org.springframework-version}</version>
    			<exclusions>
    				<!-- Exclude Commons Logging in favor of SLF4j -->
    				<exclusion>
    					<groupId>commons-logging</groupId>
    					<artifactId>commons-logging</artifactId>
    				 </exclusion>
    			</exclusions>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-jdbc</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-tx</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-webmvc</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    		
    		<!-- Ehcache -->
    		<dependency>
           		<groupId>net.sf.ehcache</groupId>
    	       	<artifactId>ehcache</artifactId>
    	       	<version>${ehcache.version}</version>
    	       	<type>pom</type>
    	   	</dependency>
    	   	<dependency>
    		    <groupId>cglib</groupId>
    		    <artifactId>cglib</artifactId>
    		    <version>2.2.2</version>
    		</dependency>
    Code:
    <cache:annotation-driven />
    	
    <!-- Ehcache library setup -->
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcache" />
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <ehcache>
    	<defaultCache maxElementsInMemory="10000" eternal="false"
    		timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
    		maxElementsOnDisk="10000000" diskPersistent="false"
    		diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
    
    	<cache name="reviewsByLeague"
    		maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="300"
    		timeToLiveSeconds="600" overflowToDisk="true" />
    </ehcache>
    Code:
    @Service
    public class JdbcStadiumReviewService implements StadiumReviewService {
    
    @Cacheable(value="reviewsByLeague", key="league")
    	public List<StadiumReview> getReviews(String league) {
    // Perform call to DB to fetch list of reviews for the given league
    }
    }

  • #2
    I figure this is some sort of issue with the type of proxies created... any good tips on the best way to debug this??

    Comment


    • #3
      Anybody else seen something with the method marked as @Cacheable not having the cache being invoked??

      Comment


      • #4
        I think you need to use
        @Cacheable(value="reviewsByLeague", key="#league")

        Comment

        Working...
        X