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();
});
}
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();
});
}
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;
}
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;
}
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;
}
Aggregations