Search in sources :

Example 6 with RedisCacheManager

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

the class CacheAutoConfigurationTests method redisCacheExplicit.

@Test
void redisCacheExplicit() {
    this.contextRunner.withUserConfiguration(RedisConfiguration.class).withPropertyValues("spring.cache.type=redis", "spring.cache.redis.time-to-live=15000", "spring.cache.redis.cacheNullValues=false", "spring.cache.redis.keyPrefix=prefix", "spring.cache.redis.useKeyPrefix=true").run((context) -> {
        RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager.class);
        assertThat(cacheManager.getCacheNames()).isEmpty();
        RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
        assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofSeconds(15));
        assertThat(redisCacheConfiguration.getAllowCacheNullValues()).isFalse();
        assertThat(redisCacheConfiguration.getKeyPrefixFor("MyCache")).isEqualTo("prefixMyCache::");
        assertThat(redisCacheConfiguration.usePrefix()).isTrue();
    });
}
Also used : RedisCacheConfiguration(org.springframework.data.redis.cache.RedisCacheConfiguration) RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) Test(org.junit.jupiter.api.Test)

Example 7 with RedisCacheManager

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

the class CacheAutoConfigurationTests method redisCacheExplicitWithCaches.

@Test
void redisCacheExplicitWithCaches() {
    this.contextRunner.withUserConfiguration(RedisConfiguration.class).withPropertyValues("spring.cache.type=redis", "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar").run((context) -> {
        RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager.class);
        assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
        RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
        assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofMinutes(0));
        assertThat(redisCacheConfiguration.getAllowCacheNullValues()).isTrue();
        assertThat(redisCacheConfiguration.getKeyPrefixFor("test")).isEqualTo("test::");
        assertThat(redisCacheConfiguration.usePrefix()).isTrue();
    });
}
Also used : RedisCacheConfiguration(org.springframework.data.redis.cache.RedisCacheConfiguration) RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) Test(org.junit.jupiter.api.Test)

Example 8 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project commons by terran4j.

the class HedisConfiguration method cacheManager.

@Bean
public CacheManager cacheManager(RedisTemplate<?, ?> redisTemplate) {
    RedisCacheManager manager = new RedisCacheManager(redisTemplate);
    // 设置默认过期时间
    manager.setDefaultExpiration(defaultExpiration);
    return manager;
}
Also used : RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project spring-cloud by Rogge666.

the class RedisConfig method cacheManager.

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

Example 10 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project springBoot-learn-demo by nbfujx.

the class RedisCacheConfig method cacheManager.

@Bean
public CacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate) {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
    cacheManager.setDefaultExpiration(1800);
    return cacheManager;
}
Also used : RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) Bean(org.springframework.context.annotation.Bean)

Aggregations

RedisCacheManager (org.springframework.data.redis.cache.RedisCacheManager)15 Bean (org.springframework.context.annotation.Bean)10 RedisCacheConfiguration (org.springframework.data.redis.cache.RedisCacheConfiguration)5 Test (org.junit.jupiter.api.Test)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 FatalBeanException (org.springframework.beans.FatalBeanException)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 RedisCache (org.springframework.data.redis.cache.RedisCache)1