fix(tenant): 租户缓存增加注释

This commit is contained in:
airhead 2022-08-25 15:53:01 +08:00
parent 310b5b00a7
commit 8527bd3c77
2 changed files with 18 additions and 5 deletions

View File

@ -118,11 +118,18 @@ public class YudaoTenantAutoConfiguration {
};
}
@Bean
@Primary
public RedisCacheManager tenantRedisCacheManager(
RedisTemplate<String, Object> redisTemplate,
RedisCacheConfiguration redisCacheConfiguration) {
/**
* 引入租户时tenantRedisCacheManager为主Bean
*
* @param redisTemplate
* @param redisCacheConfiguration
* @return
*/
@Bean
@Primary
public RedisCacheManager tenantRedisCacheManager(
RedisTemplate<String, Object> redisTemplate,
RedisCacheConfiguration redisCacheConfiguration) {
RedisCacheWriter cacheWriter =
RedisCacheWriter.nonLockingRedisCacheWriter(
Objects.requireNonNull(redisTemplate.getConnectionFactory()));

View File

@ -8,10 +8,15 @@ import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
/**
* 租户缓存管理
*
* 为cacheName增加自动增加租户表示格式name+":"+tenantId
*
* @author airhead
*/
@Slf4j
public class TenantRedisCacheManager extends RedisCacheManager {
public TenantRedisCacheManager(
RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {
super(cacheWriter, defaultCacheConfiguration);
@ -19,6 +24,7 @@ public class TenantRedisCacheManager extends RedisCacheManager {
@Override
public Cache getCache(String name) {
//租户未设置时返回原始name
if (TenantContextHolder.getTenantId() == null) {
return super.getCache(name);
}