3

I've seen many incarnations of this same issue but I think I've tried all the fixes - my usage is quite straightforward.

I had been using Ehcache which also didn't work. So, to rule out Ehcache issues and help point to something more fundamental, I moved to SimpleCacheManager and ConcurrentMapCacheFactoryBean.

Here's my config:

<cache:annotation-driven/>

<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
      <property name="caches">
        <set>
          <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="parentAppIds"/>
        </set>
      </property>
    </bean>

Here's my method:

    @Cacheable(value="parentAppIds", key="accountNumber")
        public Long findApplicationId(String accountNsc, String accountNumber) throws EMSException {
....
}

This is a method on an interface, who's implementing class is Spring managed @Service("foo")

I tried using 'p0' as is suggested here but to no avail. I have no compilation problems and no errors in my server logs so I'm confident that I have all that is necessary on my classpath; and that Namespaces are all fine, since I'm using STS for that - so I left out pom.xml and spring Namespace declarations to block noise.

I'm using Spring 3.1; Java 1.5 and Websphere 6.1

The symptom is that the method is being visited with the same parameters repeatedly.

Please help - I'm hungry and refuse to go for lunch until I nail this.

note: I have simplified my @Cacheable declaration my actual one is

@Cacheable(value="parentAppIds", key="#p0.concat('-').concat(#p1)")

Neither work.

Thanks.

** Edit - I've ruled out Websphere as being a problem by creating a test rig with

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(...)

which mimics what is happening. @Cacheable is simply not working. There must be something blindingly obvious that I am missing. (I've had lunch now)

Community
  • 1
  • 1
HellishHeat
  • 2,280
  • 4
  • 31
  • 37
  • I had a problem with Spring Caching because I called the annotated method from within the same class, forgetting that this is not how proxies work. You say the annotation is on an interface so that probably isn't your problem, I'm just throwing it out there. – Tom McIntyre Dec 10 '13 at 12:34
  • check this tutorial http://java2practice.com/2013/03/23/spring-cacheable-and-cacheevict-explained-in-simple-terms/ – Ramesh Kotha Dec 10 '13 at 15:55

2 Answers2

4

My issue is resolved. Unfortunately I cannot pinpoint exactly where my issue lay. Certainly, all that is required is that which I have mentioned in my question.

TO fix this, I tidied up my Spring configuration a bit and cleared my browser and application server cache and temp directories. I did a full clean install and cache is now working.

It is possible that I was testing with an earlier version which did not include this important line in the application config:

<cache:annotation-driven/>

I had omitted that at the start. Maybe my adding of that was not picked up until now. Otherwise I am stumped. Thanks for your time.

HellishHeat
  • 2,280
  • 4
  • 31
  • 37
0

Did you perhaps change

@Cacheable(value="parentAppIds", key="accountNumber")

to

@Cacheable(value="parentAppIds", key="#accountNumber")

as adding the # that removed one error for me while trying to get caching working.

ben3000
  • 4,629
  • 6
  • 24
  • 43