I am developing a web application using Spring MVC and am using Spring cache abstraction with Redis to cache database queries. But I cannot create multiple cache repositories using @Cacheable .
@Cacheable("acache") public String atest(int i) { return "a"; } @Cacheable("bcache") public String btest(int i) { return "b"; } ... ... String s = atest(1); String r = btest(1);
Using redis, both s and r have the same value << 24>. Although I cache two methods in different caches, this does not seem to have an effect.
But this works fine when I use Spring SimpleCacheManager .
Spring bean Configuration for Redis:
<cache:annotation-driven /> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:hostName="${redis.host-name}" p:port="${redis.port}" p:usePool="true"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connectionFactory-ref="jedisConnectionFactory"/> <bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager" c:template-ref="redisTemplate"> </bean>
spring spring-mvc caching redis
Rohan laishram
source share