@Cacheable#cacheNames 与 Redis 无关吗?
Does @Cacheable#cacheNames have nothing to do with Redis?
我的服务注释如下
@Cacheable(cacheNames = {"some"},
key = "{#req.some, #req.other, #req.property}")
public List<Some> listSome(SomeReq req) {
..
}
它似乎有效,我通过 Medis 看到了这些密钥。
(coupon
是 spring.cache.redis.key-prefix
的值。)
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
cacheNames
在哪里?
如果我添加具有相同键模式的其他服务方法,是否可能发生冲突?
@Cacheable(cacheNames = {"someOther"},
key = "{#req.some, #req.other, #req.property}")
List<SomeOther> listSomeOthers(SomeOtherReq req) {
}
Is it possible to collide if I add other service method with same pattern of keys?
不,因为 cacheNames
是(工作方式类似)命名空间,因此您可以在不同的命名空间中使用相同的键。
我正在为我自己的问题回答更多的问题。
简单地说,我需要为 RedisCacheManager
定义一个 bean 来使 cacheNames
工作。
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
final RedisCacheManager cacheManager = RedisCacheManager.builder(connectionFactory)
.cacheDefaults(defaultCacheConfig())
.build();
return cacheManager;
}
如您所见,我没有对 defaultCacheConfig()
进行任何更改。
键是 属性 前缀为 {cacheName}::
。
我的服务注释如下
@Cacheable(cacheNames = {"some"},
key = "{#req.some, #req.other, #req.property}")
public List<Some> listSome(SomeReq req) {
..
}
它似乎有效,我通过 Medis 看到了这些密钥。
(coupon
是 spring.cache.redis.key-prefix
的值。)
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
coupon{Some},{Other},{Property}
cacheNames
在哪里?
如果我添加具有相同键模式的其他服务方法,是否可能发生冲突?
@Cacheable(cacheNames = {"someOther"},
key = "{#req.some, #req.other, #req.property}")
List<SomeOther> listSomeOthers(SomeOtherReq req) {
}
Is it possible to collide if I add other service method with same pattern of keys?
不,因为 cacheNames
是(工作方式类似)命名空间,因此您可以在不同的命名空间中使用相同的键。
我正在为我自己的问题回答更多的问题。
简单地说,我需要为 RedisCacheManager
定义一个 bean 来使 cacheNames
工作。
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
final RedisCacheManager cacheManager = RedisCacheManager.builder(connectionFactory)
.cacheDefaults(defaultCacheConfig())
.build();
return cacheManager;
}
如您所见,我没有对 defaultCacheConfig()
进行任何更改。
键是 属性 前缀为 {cacheName}::
。