0

I am using redis as my spring cache implementation. And the official doc says we should configure the cache manager like this:

<!-- Old version -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"
        c:template-ref="redisTemplate">

And it works fine when version of jedis = 2.0.0 and version of spring-data-redis = 1.0.2.RELEASE.

But in more recent versions (e.g. jedis = 2.5.2 and spring-data-redis = 1.3.4.RELEASE), the config above is not working. Instead, it throws the an exception, saying "loadCaches must not return an empty Collection". Then I referred to it and googled it again, and now the configuration file is something like this:

<!-- New Version -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"
        c:template-ref="redisTemplate">
    <property name="cacheNames">
        <map>
            <bean id="someid" class="someclass" p:name="somename"/>
        </map>
    </property>
</bean>

Now it doesn't complain about empty collection, but something else about initialization.

So there are another 2 questions here:

  1. Inside the cacheNames property, I see others are using "list", "set" and "map". What are the differences?
  2. How to configure the bean inside?

I have been struggling with this bean setup for a couple of days.. Could you please help me on them? Thanks in advance

maxwong
  • 63
  • 2
  • 7

2 Answers2

0

As a hint, please see the org.springframework.cache.annotation.EnableCaching annotation.

Inside it talks about the CacheManager interface and how it works.

As a quick 'get you going', you need to specify the names of the caches that you will want to be using (such as when you use @CacheConfig(cacheNames='...') or @Cacheable(value = '...'). The idea is that you are creating logical groupings of related 'things' to be cached, ie: Books, Cars, Loans, etc.

In a BookService, you would use something like @CacheConfig(cacheNames='Books').

Hope that helps!

Jaymes Bearden
  • 2,009
  • 2
  • 21
  • 24
0

I have faced the similar issue on using Jedis with spring-data-redis. One of the finding which I have is, spring-data-redis is very specific about Jedis version. For my case, Spring-data-redis 1.5.0.RELEASE is compatible with Jedis 2.6.2.

For your case, as refer to the link below, look for compile dependencies section, you will find out 1.3.4.RELEASE is compatible with Jedis 2.4.1. I believe your problem will be solve once you change your POM file Jedis version.

http://mvnrepository.com/artifact/org.springframework.data/spring-data-redis/1.3.4.RELEASE

kwky
  • 389
  • 3
  • 9