org.springframework.data.redis.cache.RedisCacheWriter Java Examples

The following examples show how to use org.springframework.data.redis.cache.RedisCacheWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: mica   Author: lets-mica   File: MicaRedisCacheAutoConfiguration.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Primary
@Bean("redisCacheManager")
public RedisCacheManager redisCacheManager(RedisConnectionFactory connectionFactory) {
	RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
	RedisCacheConfiguration cacheConfiguration = this.determineConfiguration();
	List<String> cacheNames = this.cacheProperties.getCacheNames();
	Map<String, RedisCacheConfiguration> initialCaches = new LinkedHashMap<>();
	if (!cacheNames.isEmpty()) {
		Map<String, RedisCacheConfiguration> cacheConfigMap = new LinkedHashMap<>(cacheNames.size());
		cacheNames.forEach(it -> cacheConfigMap.put(it, cacheConfiguration));
		initialCaches.putAll(cacheConfigMap);
	}
	boolean allowInFlightCacheCreation = true;
	boolean enableTransactions = false;
	RedisAutoCacheManager cacheManager = new RedisAutoCacheManager(redisCacheWriter, cacheConfiguration, initialCaches, allowInFlightCacheCreation);
	cacheManager.setTransactionAware(enableTransactions);
	return this.customizerInvoker.customize(cacheManager);
}
 
Example #2
Source Project: syhthems-platform   Author: ehaut   File: RedisCacheConfig.java    License: MIT License 6 votes vote down vote up
@Override
@Bean
@Primary
public CacheManager cacheManager() {
    final RedisCacheWriter redisCacheWriter =
            RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
    final RedisCacheConfiguration defaultCacheConfig =
            RedisCacheConfiguration.defaultCacheConfig()

                    // 不缓存 null 值
                    .disableCachingNullValues()
                    // 使用注解时的序列化、反序列化对
                    .serializeKeysWith(stringPair)
                    .serializeValuesWith(jacksonPair)

                    .prefixKeysWith("syhthems:cache:");
    return new RedisCacheManager(redisCacheWriter, defaultCacheConfig);
}
 
Example #3
Source Project: syhthems-platform   Author: ehaut   File: RedisCacheConfig.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
@Bean
public CacheManager JDKCacheManager() {
    final RedisCacheWriter redisCacheWriter =
            RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
    final RedisCacheConfiguration defaultCacheConfig =
            RedisCacheConfiguration.defaultCacheConfig()

                    // 不缓存 null 值
                    .disableCachingNullValues()
                    // 使用注解时的序列化、反序列化对
                    .serializeKeysWith(stringPair)
                    .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.java()))
                    .prefixKeysWith("syhthems:cache:");
    return new RedisCacheManager(redisCacheWriter, defaultCacheConfig);
}
 
Example #4
Source Project: spring-boot-vue-admin   Author: Zoctan   File: RedisCacheConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
@Override
public CacheManager cacheManager() {
  // 初始化一个 RedisCacheWriter
  final RedisCacheWriter redisCacheWriter =
      RedisCacheWriter.nonLockingRedisCacheWriter(this.redisConnectionFactory);
  final RedisCacheConfiguration defaultCacheConfig =
      RedisCacheConfiguration.defaultCacheConfig()
          // 不缓存 null 值
          // .disableCachingNullValues()
          // 使用注解时的序列化、反序列化对
          .serializeKeysWith(MyRedisCacheManager.STRING_PAIR)
          .serializeValuesWith(MyRedisCacheManager.FASTJSON_PAIR);
  // 初始化RedisCacheManager
  return new MyRedisCacheManager(redisCacheWriter, defaultCacheConfig);
}
 
Example #5
Source Project: faster-framework-project   Author: faster-framework   File: RedisCacheAutoConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 管理缓存
 *
 * @return
 */
@Bean
public CacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory,
                                      RedisGenericCacheProcessor redisGenericCacheProcessor,
                                      ObjectMapper objectMapper,
                                      CacheProperties cacheProperties,
                                      CacheManagerCustomizers customizerInvoker,
                                      ResourceLoader resourceLoader
) {

    RedisGenericCacheManager redisGenericCacheManager = new RedisGenericCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory),
            determineConfiguration(resourceLoader.getClassLoader(), cacheProperties));
    redisGenericCacheManager.setCacheProperties(cacheProperties);
    redisGenericCacheManager.setGenericCacheMap(redisGenericCacheProcessor.getGenericCacheMap());
    redisGenericCacheManager.setObjectMapper(objectMapper);
    return customizerInvoker.customize(redisGenericCacheManager);
}
 
Example #6
Source Project: jim-framework   Author: jiangmin168168   File: CustomizedRedisCacheManager.java    License: Apache License 2.0 6 votes vote down vote up
public CustomizedRedisCacheManager(
        RedisConnectionFactory connectionFactory,
        RedisOperations redisOperations,
        List<CacheItemConfig> cacheItemConfigList) {

    this(
            RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory),
            RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(30)),
            cacheItemConfigList
                    .stream()
                    .collect(Collectors.toMap(CacheItemConfig::getName,cacheItemConfig -> {
                        RedisCacheConfiguration cacheConfiguration =
                                RedisCacheConfiguration
                                        .defaultCacheConfig()
                                        .entryTtl(Duration.ofSeconds(cacheItemConfig.getExpiryTimeSecond()))
                                        .prefixKeysWith(cacheItemConfig.getName());
                        return cacheConfiguration;
                    }))
    );
    this.redisOperations=redisOperations;
    CacheContainer.init(cacheItemConfigList);

}
 
Example #7
Source Project: open-cloud   Author: liuyadu   File: RedisCacheAutoConfiguration.java    License: MIT License 5 votes vote down vote up
/**
 * 配置缓存管理器
 *
 * @param redisConnectionFactory
 * @return
 */
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
    // 生成一个默认配置,通过config对象即可对缓存进行自定义配置
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
    // 设置缓存的默认过期时间,也是使用Duration设置
    redisCacheConfiguration = redisCacheConfiguration
            // 设置缓存有效期一小时
            .entryTtl(Duration.ofHours(1));
    return RedisCacheManager
            .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
            .cacheDefaults(redisCacheConfiguration).build();
}
 
Example #8
Source Project: mall4j   Author: gz-yami   File: RedisCacheConfig.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {

	RedisCacheManager redisCacheManager = new RedisCacheManager(
            RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory),
            // 默认策略,未配置的 key 会使用这个
            this.getRedisCacheConfigurationWithTtl(3600),
            // 指定 key 策略
            this.getRedisCacheConfigurationMap()
        );
	redisCacheManager.setTransactionAware(true);
    return redisCacheManager;
}
 
Example #9
Source Project: mall-learning   Author: macrozheng   File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //设置Redis缓存有效期为1天
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
            .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer())).entryTtl(Duration.ofDays(1));
    return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
}
 
Example #10
Source Project: White-Jotter   Author: Antabot   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //设置Redis缓存有效期为1天
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
            .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer())).entryTtl(Duration.ofDays(1));
    return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
}
 
Example #11
Source Project: kvf-admin   Author: kalvinGit   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
@Primary
    @Bean
    public CacheManager cacheManager(RedisConnectionFactory factory) {
        //对象的序列化
        RedisSerializationContext.SerializationPair valueSerializationPair
                = RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer());
        //全局redis缓存过期时间
        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
                .entryTtl(Duration.ofDays(1))
//                .serializeKeysWith()
                .serializeValuesWith(valueSerializationPair);

        return new RedisCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(factory), redisCacheConfiguration);
    }
 
Example #12
Source Project: light-reading-cloud   Author: Zealon159   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
/** 缓存管理器 */
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
    //初始化一个RedisCacheWriter
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //设置CacheManager的值序列化方式为json序列化
    RedisSerializer<Object> jsonSerializer = new GenericJackson2JsonRedisSerializer();
    RedisSerializationContext.SerializationPair<Object> pair = RedisSerializationContext.SerializationPair.fromSerializer(jsonSerializer);
    RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair);
    //设置默认超过期时间是30秒
    defaultCacheConfig = defaultCacheConfig.entryTtl(Duration.ofSeconds(300));
    //初始化RedisCacheManager
    return new RedisCacheManager(redisCacheWriter, defaultCacheConfig);
}
 
Example #13
Source Project: light-reading-cloud   Author: Zealon159   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
/** 缓存管理器 */
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
    //初始化一个RedisCacheWriter
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //设置CacheManager的值序列化方式为json序列化
    RedisSerializer<Object> jsonSerializer = new GenericJackson2JsonRedisSerializer();
    RedisSerializationContext.SerializationPair<Object> pair = RedisSerializationContext.SerializationPair.fromSerializer(jsonSerializer);
    RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair);
    //设置默认超过期时间是30秒
    defaultCacheConfig = defaultCacheConfig.entryTtl(Duration.ofSeconds(300));
    //初始化RedisCacheManager
    return new RedisCacheManager(redisCacheWriter, defaultCacheConfig);
}
 
Example #14
Source Project: light-reading-cloud   Author: Zealon159   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
/** 缓存管理器 */
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
    //初始化一个RedisCacheWriter
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //设置CacheManager的值序列化方式为json序列化
    RedisSerializer<Object> jsonSerializer = new GenericJackson2JsonRedisSerializer();
    RedisSerializationContext.SerializationPair<Object> pair = RedisSerializationContext.SerializationPair.fromSerializer(jsonSerializer);
    RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair);
    //设置默认超过期时间是30秒
    defaultCacheConfig = defaultCacheConfig.entryTtl(Duration.ofSeconds(300));
    //初始化RedisCacheManager
    return new RedisCacheManager(redisCacheWriter, defaultCacheConfig);
}
 
Example #15
Source Project: springboot-shiro   Author: zhangyd-c   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory factory) {
    return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(factory))
            // 默认缓存过期时间:天
            .cacheDefaults(RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(30)))
            .transactionAware()
            .build();
}
 
Example #16
Source Project: mall   Author: macrozheng   File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //设置Redis缓存有效期为1天
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
            .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer())).entryTtl(Duration.ofDays(1));
    return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
}
 
Example #17
Source Project: hdw-dubbo   Author: JacksonTu   File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //设置Redis缓存有效期为1天
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
            .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer())).entryTtl(Duration.ofDays(1));
    return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
}
 
Example #18
Source Project: DimpleBlog   Author: DimpleFeng   File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
    RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);

    RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig()
            .entryTtl(Duration.ofHours(1))
            .serializeKeysWith(MyRedisCacheManager.STRING_PAIR)
            .serializeValuesWith(MyRedisCacheManager.FASTJSON_PAIR);
    return new MyRedisCacheManager(cacheWriter, defaultCacheConfig);
}
 
Example #19
Source Project: agile-service-old   Author: choerodon   File: RedisCacheConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
            .entryTtl(Duration.ofHours(24)); // 设置缓存有效期一小时
    return RedisCacheManager
            .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
            .cacheDefaults(redisCacheConfiguration).transactionAware().build();
}
 
Example #20
Source Project: JetfireCloud   Author: jorrellz   File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    //全局redis缓存过期时间
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(1));
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisTemplate.getConnectionFactory());
    return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
}
 
Example #21
Source Project: x7   Author: x-ream   File: RedisCacheConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
    return new RedisCacheManager(
            RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory),
            this.getRedisCacheConfigurationWithTtl(entryTTL),  // 默认策略,未配置的 key 会使用这个
            this.getRedisCacheConfigurationMap()               // 指定 key 策略
    );
}
 
Example #22
Source Project: blade-tool   Author: chillzhuang   File: RedisTemplateConfiguration.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
	RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
		.entryTtl(Duration.ofHours(1));
	return RedisCacheManager
		.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
		.cacheDefaults(redisCacheConfiguration).build();
}
 
Example #23
Source Project: demo-project   Author: FleyX   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
/**
 * 设置缓存管理器,这里可以配置默认过期时间等
 *
 * @param connectionFactory 连接池
 * @return
 */
@Bean
public CacheManager cacheManager(JedisConnectionFactory jedisConnectionFactory) {
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration
            .defaultCacheConfig()
            .entryTtl(Duration.ofSeconds(60));
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(jedisConnectionFactory);
    RedisCacheManager manager = new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
    return manager;
}
 
Example #24
Source Project: OneBlog   Author: zhangyd-c   File: RedisConfig.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory factory) {
    return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(factory))
            // 默认缓存过期时间:天
            .cacheDefaults(RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(30)))
            .transactionAware()
            .build();
}
 
Example #25
Source Project: biliob_backend   Author: Jannchie   File: RedisConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
    // 初始化一个RedisCacheWriter
    RedisCacheWriter redisCacheWriter =
            RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
    // 初始化RedisCacheManager
    return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration());
}
 
Example #26
Source Project: jim-framework   Author: jiangmin168168   File: CustomizedRedisCacheManager.java    License: Apache License 2.0 5 votes vote down vote up
public CustomizedRedisCacheManager(
        RedisCacheWriter redisCacheWriter
        ,RedisCacheConfiguration redisCacheConfiguration,
        Map<String, RedisCacheConfiguration> redisCacheConfigurationMap) {
    super(redisCacheWriter,redisCacheConfiguration,redisCacheConfigurationMap);
    this.redisCacheWriter=redisCacheWriter;
    this.defaultRedisCacheConfiguration=redisCacheConfiguration;
}
 
Example #27
Source Project: bird-java   Author: liuxx001   File: RedisCacheConfigurer.java    License: MIT License 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
    RedisCacheWriter cacheWriter = RedisCacheWriter.lockingRedisCacheWriter(connectionFactory);

    RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
            .entryTtl(Duration.ofMinutes(10))
            .prefixKeysWith(cachePrefix + ":")
            .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));

    return new RedisCacheManager(cacheWriter, cacheConfiguration);
}
 
Example #28
Source Project: SpringCloud   Author: zhoutaoo   File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
    public CacheManager cacheManager(RedisConnectionFactory factory) {
        //对象的序列化
        RedisSerializationContext.SerializationPair valueSerializationPair
                = RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer());
        //全局redis缓存过期时间
        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
                .entryTtl(Duration.ofDays(1))
//                .serializeKeysWith()
                .serializeValuesWith(valueSerializationPair);

        return new RedisCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(factory), redisCacheConfiguration);
    }
 
Example #29
Source Project: mica   Author: lets-mica   File: RedisAutoCacheManager.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public RedisAutoCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
							 Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) {
	super(cacheWriter, defaultCacheConfiguration, initialCacheConfigurations, allowInFlightCacheCreation);
}
 
Example #30
Source Project: spring-microservice-exam   Author: wells2333   File: MultitenantCacheManager.java    License: MIT License 4 votes vote down vote up
public MultitenantCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
                               Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) {
    super(cacheWriter, defaultCacheConfiguration, initialCacheConfigurations, allowInFlightCacheCreation);
}