| 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.databind.DeserializationFeature;
|
- |
|
| 4 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
3 |
import com.github.benmanes.caffeine.cache.Caffeine;
|
| 5 |
import org.springframework.cache.CacheManager;
|
4 |
import org.springframework.cache.CacheManager;
|
| 6 |
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
5 |
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
| 7 |
import org.springframework.cache.annotation.EnableCaching;
|
6 |
import org.springframework.cache.annotation.EnableCaching;
|
| - |
|
7 |
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
| 8 |
import org.springframework.context.annotation.Bean;
|
8 |
import org.springframework.context.annotation.Bean;
|
| 9 |
import org.springframework.context.annotation.Configuration;
|
9 |
import org.springframework.context.annotation.Configuration;
|
| 10 |
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
- |
|
| 11 |
import org.springframework.data.redis.cache.RedisCacheManager;
|
- |
|
| 12 |
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
- |
|
| 13 |
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
- |
|
| 14 |
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
- |
|
| 15 |
|
10 |
|
| 16 |
import java.time.Duration;
|
11 |
import java.util.concurrent.TimeUnit;
|
| 17 |
|
12 |
|
| 18 |
@Configuration
|
13 |
@Configuration
|
| 19 |
@EnableCaching
|
14 |
@EnableCaching
|
| 20 |
public class CacheConfig extends CachingConfigurerSupport {
|
15 |
public class CacheConfig extends CachingConfigurerSupport {
|
| 21 |
|
16 |
|
| 22 |
@Bean
|
17 |
@Override
|
| 23 |
JedisConnectionFactory jedisConnectionFactory() {
|
- |
|
| 24 |
return new JedisConnectionFactory();
|
- |
|
| 25 |
}
|
- |
|
| 26 |
|
- |
|
| 27 |
@Bean
|
- |
|
| 28 |
public RedisCacheConfiguration cacheConfiguration() {
|
- |
|
| 29 |
ObjectMapper objectMapper = new ObjectMapper().enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
- |
|
| 30 |
return RedisCacheConfiguration.defaultCacheConfig()
|
- |
|
| 31 |
.entryTtl(Duration.ofMinutes(120))
|
- |
|
| 32 |
.disableCachingNullValues()
|
- |
|
| 33 |
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer(objectMapper)));
|
- |
|
| 34 |
}
|
- |
|
| 35 |
|
- |
|
| 36 |
@Bean
|
18 |
@Bean
|
| 37 |
public CacheManager cacheManager() {
|
19 |
public CacheManager cacheManager() {
|
| 38 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
20 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
| 39 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(5)))
|
- |
|
| 40 |
.build();
|
21 |
return cacheManager;
|
| 41 |
}
|
22 |
}
|
| 42 |
|
23 |
|
| 43 |
|
- |
|
| 44 |
@Bean
|
24 |
@Bean
|
| 45 |
public CacheManager timeoutCacheManager() {
|
25 |
public CacheManager timeoutCacheManager() {
|
| 46 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
26 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
| 47 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(5)))
|
27 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES);
|
| - |
|
28 |
cacheManager.setCaffeine(caffeine);
|
| 48 |
.build();
|
29 |
return cacheManager;
|
| 49 |
}
|
30 |
}
|
| 50 |
|
31 |
|
| 51 |
@Bean
|
32 |
@Bean
|
| 52 |
public CacheManager timeout15CacheManager() {
|
33 |
public CacheManager timeout15CacheManager() {
|
| 53 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
34 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
| 54 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(15)))
|
35 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(15, TimeUnit.MINUTES);
|
| - |
|
36 |
cacheManager.setCaffeine(caffeine);
|
| 55 |
.build();
|
37 |
return cacheManager;
|
| 56 |
}
|
38 |
}
|
| 57 |
|
39 |
|
| 58 |
@Bean
|
40 |
@Bean
|
| 59 |
public CacheManager oneDayCacheManager() {
|
41 |
public CacheManager oneDayCacheManager() {
|
| 60 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
42 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
| 61 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofHours(8)))
|
43 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(6, TimeUnit.HOURS);
|
| - |
|
44 |
cacheManager.setCaffeine(caffeine);
|
| 62 |
.build();
|
45 |
return cacheManager;
|
| 63 |
}
|
46 |
}
|
| 64 |
|
47 |
|
| 65 |
|
48 |
|
| 66 |
@Bean
|
49 |
@Bean
|
| 67 |
public CacheManager twoMintimeoutCacheManager() {
|
50 |
public CacheManager twoMintimeoutCacheManager() {
|
| 68 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
51 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
| 69 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(2)))
|
52 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(2, TimeUnit.MINUTES);
|
| - |
|
53 |
cacheManager.setCaffeine(caffeine);
|
| 70 |
.build();
|
54 |
return cacheManager;
|
| 71 |
}
|
55 |
}
|
| 72 |
|
56 |
|
| 73 |
@Bean
|
57 |
@Bean
|
| 74 |
public CacheManager thirtyMinsTimeOutCacheManager() {
|
58 |
public CacheManager thirtyMinsTimeOutCacheManager() {
|
| - |
|
59 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
| - |
|
60 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES);
|
| - |
|
61 |
cacheManager.setCaffeine(caffeine);
|
| - |
|
62 |
return cacheManager;
|
| - |
|
63 |
}
|
| - |
|
64 |
|
| - |
|
65 |
|
| - |
|
66 |
/* @Bean
|
| - |
|
67 |
JedisConnectionFactory jedisConnectionFactory() {
|
| - |
|
68 |
return new JedisConnectionFactory();
|
| - |
|
69 |
}
|
| - |
|
70 |
|
| - |
|
71 |
@Autowired
|
| - |
|
72 |
ObjectMapper objectMapper;
|
| - |
|
73 |
|
| - |
|
74 |
@Bean
|
| - |
|
75 |
public RedisCacheConfiguration cacheConfiguration() {
|
| - |
|
76 |
return RedisCacheConfiguration.defaultCacheConfig()
|
| - |
|
77 |
.entryTtl(Duration.ofMinutes(120))
|
| - |
|
78 |
.disableCachingNullValues()
|
| - |
|
79 |
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(
|
| - |
|
80 |
new GenericJackson2JsonRedisSerializer(objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY))));
|
| - |
|
81 |
}
|
| - |
|
82 |
|
| - |
|
83 |
@Bean
|
| - |
|
84 |
public CacheManager cacheManager() {
|
| 75 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
85 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
| 76 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(30)))
|
86 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(5)))
|
| 77 |
.build();
|
87 |
.build();
|
| 78 |
}
|
88 |
}*/
|
| 79 |
|
89 |
|
| 80 |
}
|
90 |
}
|
| 81 |
|
91 |
|