Java Code Examples for org.springframework.data.redis.cache.RedisCacheWriter#nonLockingRedisCacheWriter()

The following examples show how to use org.springframework.data.redis.cache.RedisCacheWriter#nonLockingRedisCacheWriter() . 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 File: RedisCacheConfig.java    From spring-boot-vue-admin with 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 2
Source File: CustomizedRedisCacheManager.java    From jim-framework with 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 3
Source File: RedisCacheAutoConfiguration.java    From faster-framework-project with 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 4
Source File: MicaRedisCacheAutoConfiguration.java    From mica with 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 5
Source File: RedisCacheConfig.java    From syhthems-platform with 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 6
Source File: RedisCacheConfig.java    From syhthems-platform with 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 7
Source File: RedisConfig.java    From light-reading-cloud with 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 8
Source File: RedisConfig.java    From light-reading-cloud with 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 9
Source File: RedisConfig.java    From light-reading-cloud with 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 10
Source File: RedisConfig.java    From SpringCloud with 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 11
Source File: RedisConfig.java    From White-Jotter with 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 12
Source File: RedisConfig.java    From mall-learning with 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 13
Source File: RedisConfig.java    From mall with 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 14
Source File: RedisConfig.java    From hdw-dubbo with 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 15
Source File: RedisConfig.java    From DimpleBlog with 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 16
Source File: RedisConfig.java    From JetfireCloud with 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 17
Source File: RedisCacheConfig.java    From x7 with 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 18
Source File: RedisConfig.java    From demo-project with 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 19
Source File: RedisConfig.java    From biliob_backend with 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 20
Source File: RedisCacheConfig.java    From mall4j with 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;
}