Search in sources :

Example 1 with Redis

use of org.springframework.boot.autoconfigure.cache.CacheProperties.Redis in project spring-boot by spring-projects.

the class RedisCacheConfiguration method createConfiguration.

private org.springframework.data.redis.cache.RedisCacheConfiguration createConfiguration(CacheProperties cacheProperties, ClassLoader classLoader) {
    Redis redisProperties = cacheProperties.getRedis();
    org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration.defaultCacheConfig();
    config = config.serializeValuesWith(SerializationPair.fromSerializer(new JdkSerializationRedisSerializer(classLoader)));
    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;
}
Also used : JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) Redis(org.springframework.boot.autoconfigure.cache.CacheProperties.Redis)

Example 2 with Redis

use of org.springframework.boot.autoconfigure.cache.CacheProperties.Redis in project loc-framework by lord-of-code.

the class RedisCacheAutoConfiguration method determineConfiguration.

private org.springframework.data.redis.cache.RedisCacheConfiguration determineConfiguration() {
    Redis redisProperties = this.cacheProperties.getRedis();
    org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration.defaultCacheConfig();
    Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    om.setSerializationInclusion(Include.NON_NULL);
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    jackson2JsonRedisSerializer.setObjectMapper(om);
    config = config.serializeKeysWith(SerializationPair.fromSerializer(new StringRedisSerializer()));
    config = config.serializeValuesWith(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;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) Redis(org.springframework.boot.autoconfigure.cache.CacheProperties.Redis) Jackson2JsonRedisSerializer(org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer) RedisCacheConfiguration(org.springframework.data.redis.cache.RedisCacheConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Redis (org.springframework.boot.autoconfigure.cache.CacheProperties.Redis)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RedisCacheConfiguration (org.springframework.data.redis.cache.RedisCacheConfiguration)1 Jackson2JsonRedisSerializer (org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer)1 JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1