Subversion Repositories SmartDukaan

Rev

Rev 30213 | Rev 30305 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30213 Rev 30289
Line 1... Line 1...
1
package com.spice.profitmandi.dao.config;
1
package com.spice.profitmandi.dao.config;
2
 
2
 
-
 
3
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-
 
4
import com.fasterxml.jackson.databind.ObjectMapper;
-
 
5
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
3
import com.github.benmanes.caffeine.cache.Caffeine;
6
import com.github.benmanes.caffeine.cache.Caffeine;
-
 
7
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.cache.CacheManager;
8
import org.springframework.cache.CacheManager;
5
import org.springframework.cache.annotation.CachingConfigurerSupport;
9
import org.springframework.cache.annotation.CachingConfigurerSupport;
6
import org.springframework.cache.annotation.EnableCaching;
10
import org.springframework.cache.annotation.EnableCaching;
7
import org.springframework.cache.caffeine.CaffeineCacheManager;
11
import org.springframework.cache.caffeine.CaffeineCacheManager;
8
import org.springframework.context.annotation.Bean;
12
import org.springframework.context.annotation.Bean;
9
import org.springframework.context.annotation.Configuration;
13
import org.springframework.context.annotation.Configuration;
-
 
14
import org.springframework.data.redis.cache.RedisCacheConfiguration;
-
 
15
import org.springframework.data.redis.cache.RedisCacheManager;
-
 
16
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
-
 
17
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
-
 
18
import org.springframework.data.redis.serializer.RedisSerializationContext;
10
 
19
 
-
 
20
import java.time.Duration;
11
import java.util.concurrent.TimeUnit;
21
import java.util.concurrent.TimeUnit;
12
 
22
 
13
@Configuration
23
@Configuration
14
@EnableCaching
24
@EnableCaching
15
public class CacheConfig extends CachingConfigurerSupport {
25
public class CacheConfig extends CachingConfigurerSupport {
Line 58... Line 68...
58
	public CacheManager thirtyMinsTimeOutCacheManager() {
68
	public CacheManager thirtyMinsTimeOutCacheManager() {
59
		CaffeineCacheManager cacheManager = new CaffeineCacheManager();
69
		CaffeineCacheManager cacheManager = new CaffeineCacheManager();
60
		Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES);
70
		Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES);
61
		cacheManager.setCaffeine(caffeine);
71
		cacheManager.setCaffeine(caffeine);
62
		return cacheManager;
72
		return cacheManager;
-
 
73
 
-
 
74
 
63
	}
75
	}
64
 
76
 
65
 
77
 
66
/*	@Bean
78
	@Bean
67
	JedisConnectionFactory jedisConnectionFactory() {
79
	JedisConnectionFactory jedisConnectionFactory() {
68
		return new JedisConnectionFactory();
80
		return new JedisConnectionFactory();
69
	}
81
	}
70
 
82
 
71
	@Autowired
83
	@Autowired
Line 75... Line 87...
75
	public RedisCacheConfiguration cacheConfiguration() {
87
	public RedisCacheConfiguration cacheConfiguration() {
76
		return RedisCacheConfiguration.defaultCacheConfig()
88
		return RedisCacheConfiguration.defaultCacheConfig()
77
				.entryTtl(Duration.ofMinutes(120))
89
				.entryTtl(Duration.ofMinutes(120))
78
				.disableCachingNullValues()
90
				.disableCachingNullValues()
79
				.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(
91
				.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(
-
 
92
						new GenericJackson2JsonRedisSerializer(
80
						new GenericJackson2JsonRedisSerializer(objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY))));
93
								this.getObjectMapper().enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY))));
81
	}
94
	}
82
 
95
 
-
 
96
	private ObjectMapper getObjectMapper() {
-
 
97
		ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
-
 
98
		return mapper;
-
 
99
	}
-
 
100
 
-
 
101
	//Default Cache for 6 hours
83
	@Bean
102
	@Bean
84
	public CacheManager cacheManager() {
103
	public CacheManager redisCacheManager() {
85
		return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
104
		return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
86
				.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(5)))
105
				.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofHours(6).minusMinutes(5)))
87
				.build();
106
				.build();
88
	}*/
107
	}
89
 
108
 
90
}
109
}
91
110