Search in sources :

Example 1 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project spring-boot by spring-projects.

the class RedisCacheConfiguration method cacheManager.

@Bean
public RedisCacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate) {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
    cacheManager.setUsePrefix(true);
    List<String> cacheNames = this.cacheProperties.getCacheNames();
    if (!cacheNames.isEmpty()) {
        cacheManager.setCacheNames(cacheNames);
    }
    return this.customizerInvoker.customize(cacheManager);
}
Also used : RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method redisCacheWithRedisCacheManagerBuilderCustomizer.

@Test
void redisCacheWithRedisCacheManagerBuilderCustomizer() {
    this.contextRunner.withUserConfiguration(RedisWithRedisCacheManagerBuilderCustomizerConfiguration.class).withPropertyValues("spring.cache.type=redis", "spring.cache.redis.time-to-live=15000").run((context) -> {
        RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager.class);
        RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
        assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofSeconds(10));
    });
}
Also used : RedisCacheConfiguration(org.springframework.data.redis.cache.RedisCacheConfiguration) RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) Test(org.junit.jupiter.api.Test)

Example 3 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project cu-kfs by CU-CommunityApps.

the class CacheConfiguration method cacheManager.

@Bean
public RedisCacheManager cacheManager(@Value("${redis.default.ttl}") Long redisDefaultTtl, RedisTemplate<String, String> redisTemplate, List<String> cacheNames, Map<String, Long> cacheExpires) {
    // Cornell customization: add fix to call cacheNames() method instead of using the cacheNames variable that is causing an exception
    final RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate, cacheNames(), true);
    redisCacheManager.setDefaultExpiration(redisDefaultTtl);
    redisCacheManager.setExpires(cacheExpires);
    return redisCacheManager;
}
Also used : RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) Bean(org.springframework.context.annotation.Bean)

Example 4 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project CBEC-B2B by A-Cubic.

the class RedisConfig method cacheManager.

@SuppressWarnings("rawtypes")
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
    // 设置缓存过期时间
    // 秒
    rcm.setDefaultExpiration(7200);
    return rcm;
}
Also used : RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) Bean(org.springframework.context.annotation.Bean)

Example 5 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project fw-cloud-framework by liuweijw.

the class RedisCacheConfiguration method cacheManager.

@SuppressWarnings("rawtypes")
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate);
    redisCacheManager.setDefaultExpiration(expiration);
    return redisCacheManager;
}
Also used : RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) Bean(org.springframework.context.annotation.Bean)

Aggregations

RedisCacheManager (org.springframework.data.redis.cache.RedisCacheManager)14 Bean (org.springframework.context.annotation.Bean)9 Test (org.junit.jupiter.api.Test)4 RedisCacheConfiguration (org.springframework.data.redis.cache.RedisCacheConfiguration)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 RedisCache (org.springframework.data.redis.cache.RedisCache)1