Search in sources :

Example 11 with RedisCacheManager

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

the class RedisConfig 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)

Example 12 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project new-cloud by xie-summer.

the class RedisCacheConfig method cacheManager.

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

Example 13 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)

Example 14 with RedisCacheManager

use of org.springframework.data.redis.cache.RedisCacheManager in project loc-framework by lord-of-code.

the class RedisCacheAutoConfiguration method getRedisCacheManager.

@Bean
public RedisCacheManager getRedisCacheManager(RedisConnectionFactory redisConnectionFactory) {
    CustomRedisCacheWriter customRedisCacheWriter = new CustomRedisCacheWriter(RedisCacheWriter.lockingRedisCacheWriter(redisConnectionFactory));
    RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder.fromCacheWriter(customRedisCacheWriter).cacheDefaults(determineConfiguration());
    List<String> cacheNames = this.cacheProperties.getCacheNames();
    if (!cacheNames.isEmpty()) {
        try {
            LocCustomCacheProperties customCacheProperties = resolverSetting(LocCustomCacheProperties.class, this.environment.getPropertySources());
            Map<String, RedisCacheConfiguration> map = Maps.newHashMap();
            cacheNames.forEach(name -> {
                LocCacheProperties locCacheProperties = customCacheProperties.getCustomCache().get(name);
                RedisCacheConfiguration redisCacheConfiguration = determineConfiguration();
                if (locCacheProperties.getTimeToLive() != null) {
                    redisCacheConfiguration = redisCacheConfiguration.entryTtl(locCacheProperties.getTimeToLive());
                }
                if (locCacheProperties.getKeyPrefix() != null) {
                    redisCacheConfiguration = redisCacheConfiguration.prefixKeysWith(locCacheProperties.getKeyPrefix());
                }
                if (!locCacheProperties.isCacheNullValues()) {
                    redisCacheConfiguration = redisCacheConfiguration.disableCachingNullValues();
                }
                if (!locCacheProperties.isUseKeyPrefix()) {
                    redisCacheConfiguration = redisCacheConfiguration.disableKeyPrefix();
                }
                map.put(name, redisCacheConfiguration);
            });
            builder.withInitialCacheConfigurations(map);
        } catch (FatalBeanException e) {
            log.warn("may be not config customCache properties");
        }
    }
    return builder.build();
}
Also used : RedisCacheConfiguration(org.springframework.data.redis.cache.RedisCacheConfiguration) RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) FatalBeanException(org.springframework.beans.FatalBeanException) Bean(org.springframework.context.annotation.Bean)

Example 15 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)

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