首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否可以使用redis使用Spring的缓存抽象来创建多个缓存存储?

是否可以使用redis使用Spring的缓存抽象来创建多个缓存存储?
EN

Stack Overflow用户
提问于 2013-08-09 11:10:17
回答 1查看 6.1K关注 0票数 7

我正在使用Spring开发一个web应用程序,我使用spring的缓存抽象和Redis来缓存我的数据库查询。但我无法使用@Cacheable创建多个缓存存储。

代码语言:javascript
运行
复制
@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);

使用redis,sr的值"a“相同。尽管我将这两种方法缓存在不同的缓存中,但它似乎没有任何效果。

但是,当我使用Spring的SimpleCacheManager时,这很好。

Redis的Spring配置:

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-09 12:22:38

根据文档,默认情况下,RedisCacheManager直接保存密钥,而不添加前缀(缓存名,用作命名空间)。若要更改它并避免冲突,请将“usePrefix”设置为“true”:http://static.springsource.org/spring-data/data-redis/docs/current/api/org/springframework/data/redis/cache/RedisCacheManager.html

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18145372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档