org.springframework.boot.autoconfigure.cache.CacheProperties Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.cache.CacheProperties. 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
private RedisCacheConfiguration determineConfiguration() {
	if (this.redisCacheConfiguration != null) {
		return this.redisCacheConfiguration;
	} else {
		CacheProperties.Redis redisProperties = this.cacheProperties.getRedis();
		RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
		config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer));
		if (redisProperties.getTimeToLive() != null) {
			config = config.entryTtl(redisProperties.getTimeToLive());
		}

		if (redisProperties.getKeyPrefix() != null) {
			config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());
		}

		if (!redisProperties.isCacheNullValues()) {
			config = config.disableCachingNullValues();
		}

		if (!redisProperties.isUseKeyPrefix()) {
			config = config.disableKeyPrefix();
		}

		return config;
	}
}
 
Example #2
Source Project: black-shop   Author: lizibin   File: RedisCacheAutoConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private RedisCacheConfiguration determineConfiguration(ClassLoader classLoader) {
	if (this.redisCacheConfiguration != null) {
		return this.redisCacheConfiguration;
	} else {
		CacheProperties.Redis redisProperties = this.cacheProperties.getRedis();
		RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
		config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new JdkSerializationRedisSerializer(classLoader)));
		if (redisProperties.getTimeToLive() != null) {
			config = config.entryTtl(redisProperties.getTimeToLive());
		}

		if (redisProperties.getKeyPrefix() != null) {
			config = config.prefixKeysWith(redisProperties.getKeyPrefix());
		}

		if (!redisProperties.isCacheNullValues()) {
			config = config.disableCachingNullValues();
		}

		if (!redisProperties.isUseKeyPrefix()) {
			config = config.disableKeyPrefix();
		}

		return config;
	}
}
 
Example #3
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 #4
Source Project: faster-framework-project   Author: faster-framework   File: RedisCacheAutoConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private org.springframework.data.redis.cache.RedisCacheConfiguration determineConfiguration(
        ClassLoader classLoader,
        CacheProperties cacheProperties
) {
    CacheProperties.Redis redisProperties = cacheProperties.getRedis();
    org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration
            .defaultCacheConfig();
    config = config.serializeValuesWith(RedisSerializationContext.SerializationPair
            .fromSerializer(new JdkSerializationRedisSerializer(classLoader)));
    if (redisProperties.getTimeToLive() != null) {
        config = config.entryTtl(redisProperties.getTimeToLive());
    }
    if (redisProperties.getKeyPrefix() != null) {
        config = config.prefixKeysWith(redisProperties.getKeyPrefix());
    }
    if (!redisProperties.isCacheNullValues()) {
        config = config.disableCachingNullValues();
    }
    if (!redisProperties.isUseKeyPrefix()) {
        config = config.disableKeyPrefix();
    }
    return config;
}
 
Example #5
Source Project: faster-framework-project   Author: faster-framework   File: RedisGenericCacheManager.java    License: Apache License 2.0 6 votes vote down vote up
private <T> RedisCacheConfiguration determineConfiguration(
        Type type) {
    CacheProperties.Redis redisProperties = this.cacheProperties.getRedis();
    RedisCacheConfiguration config = RedisCacheConfiguration
            .defaultCacheConfig();
    Jackson2JsonRedisSerializer<T> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(TypeFactory.defaultInstance().constructType(type));
    jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
    config = config.serializeValuesWith(RedisSerializationContext.SerializationPair
            .fromSerializer(jackson2JsonRedisSerializer));
    if (redisProperties.getTimeToLive() != null) {
        config = config.entryTtl(redisProperties.getTimeToLive());
    }
    if (redisProperties.getKeyPrefix() != null) {
        config = config.prefixKeysWith(redisProperties.getKeyPrefix());
    }
    if (!redisProperties.isCacheNullValues()) {
        config = config.disableCachingNullValues();
    }
    if (!redisProperties.isUseKeyPrefix()) {
        config = config.disableKeyPrefix();
    }
    return config;
}
 
Example #6
Source Project: mica   Author: lets-mica   File: MicaRedisCacheAutoConfiguration.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
MicaRedisCacheAutoConfiguration(RedisSerializer<Object> redisSerializer,
								CacheProperties cacheProperties,
								CacheManagerCustomizers customizerInvoker,
								ObjectProvider<RedisCacheConfiguration> redisCacheConfiguration) {
	this.redisSerializer = redisSerializer;
	this.cacheProperties = cacheProperties;
	this.customizerInvoker = customizerInvoker;
	this.redisCacheConfiguration = redisCacheConfiguration.getIfAvailable();
}
 
Example #7
Source Project: black-shop   Author: lizibin   File: RedisCacheAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
RedisCacheAutoConfiguration(CacheProperties cacheProperties,
							CacheManagerCustomizers customizerInvoker,
							ObjectProvider<RedisCacheConfiguration> redisCacheConfiguration) {
	this.cacheProperties = cacheProperties;
	this.customizerInvoker = customizerInvoker;
	this.redisCacheConfiguration = redisCacheConfiguration.getIfAvailable();
}
 
Example #8
Source Project: spring-boot-data-geode   Author: spring-projects   File: CachingProviderAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
CachingProviderAutoConfiguration(
		@Autowired(required = false) CacheProperties cacheProperties,
		@Autowired(required = false) CacheManagerCustomizers cacheManagerCustomizers) {

	this.cacheProperties = cacheProperties;
	this.cacheManagerCustomizers = cacheManagerCustomizers;
}
 
Example #9
Source Project: platform   Author: elveahuang   File: CacheConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * RedisCacheConfiguration
 * 自定义配置,支持缓存使用Json文本格式
 *
 * @return {@link RedisCacheConfiguration}
 */
@Bean
public RedisCacheConfiguration redisCacheConfiguration() {

    // ObjectMapper & GenericJackson2JsonRedisSerializer
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false);
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    objectMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
    objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
    // LocalDateTime && LocalDate
    objectMapper.registerModule(new JavaTimeModule());

    GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(objectMapper);

    // RedisCacheConfiguration
    RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
    config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(serializer));

    CacheProperties.Redis redisProperties = cacheProperties.getRedis();
    if (redisProperties.getTimeToLive() != null) {
        config = config.entryTtl(redisProperties.getTimeToLive());
    }
    if (redisProperties.getKeyPrefix() != null) {
        config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());
    }
    if (!redisProperties.isCacheNullValues()) {
        config = config.disableCachingNullValues();
    }
    if (!redisProperties.isUseKeyPrefix()) {
        config = config.disableKeyPrefix();
    }

    return config;
}
 
Example #10
J2CacheSpringCacheAutoConfiguration(CacheProperties cacheProperties, J2CacheProperties j2CacheProperties) {
    this.cacheProperties = cacheProperties;
    this.j2CacheProperties = j2CacheProperties;
}
 
Example #11
Source Project: J2Cache   Author: oschina   File: J2CacheSpringCacheAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
J2CacheSpringCacheAutoConfiguration(CacheProperties cacheProperties, J2CacheConfig j2CacheConfig) {
	this.cacheProperties = cacheProperties;
	this.j2CacheConfig = j2CacheConfig;
}
 
Example #12
Source Project: J2Cache   Author: oschina   File: J2CacheSpringCacheAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
J2CacheSpringCacheAutoConfiguration(CacheProperties cacheProperties, J2CacheConfig j2CacheConfig) {
	this.cacheProperties = cacheProperties;
	this.j2CacheConfig = j2CacheConfig;
}
 
Example #13
Source Project: loc-framework   Author: lord-of-code   File: RedisCacheAutoConfiguration.java    License: MIT License 4 votes vote down vote up
public RedisCacheAutoConfiguration(CacheProperties cacheProperties) {
  this.cacheProperties = cacheProperties;
}
 
Example #14
Source Project: spring-boot-data-geode   Author: spring-projects   File: CachingProviderAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
Optional<CacheProperties> getCacheProperties() {
	return Optional.ofNullable(this.cacheProperties);
}
 
Example #15
Source Project: platform   Author: elveahuang   File: CacheConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Autowired
public void setCacheProperties(CacheProperties cacheProperties) {
    this.cacheProperties = cacheProperties;
}