| 22009 |
ashik.ali |
1 |
package com.spice.profitmandi.dao.config;
|
|
|
2 |
|
| 30289 |
amit.gupta |
3 |
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
5 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 30213 |
amit.gupta |
6 |
import com.github.benmanes.caffeine.cache.Caffeine;
|
| 22009 |
ashik.ali |
7 |
import org.springframework.cache.CacheManager;
|
|
|
8 |
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
|
9 |
import org.springframework.cache.annotation.EnableCaching;
|
| 30213 |
amit.gupta |
10 |
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
| 22009 |
ashik.ali |
11 |
import org.springframework.context.annotation.Bean;
|
|
|
12 |
import org.springframework.context.annotation.Configuration;
|
| 35388 |
amit |
13 |
import org.springframework.context.annotation.PropertySource;
|
| 30289 |
amit.gupta |
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;
|
| 22009 |
ashik.ali |
19 |
|
| 30289 |
amit.gupta |
20 |
import java.time.Duration;
|
| 30213 |
amit.gupta |
21 |
import java.util.concurrent.TimeUnit;
|
| 22009 |
ashik.ali |
22 |
|
|
|
23 |
@Configuration
|
|
|
24 |
@EnableCaching
|
| 35388 |
amit |
25 |
@PropertySource("classpath:application.properties")
|
| 23716 |
amit.gupta |
26 |
public class CacheConfig extends CachingConfigurerSupport {
|
|
|
27 |
|
| 30213 |
amit.gupta |
28 |
@Override
|
| 22009 |
ashik.ali |
29 |
@Bean
|
| 30213 |
amit.gupta |
30 |
public CacheManager cacheManager() {
|
|
|
31 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
32 |
return cacheManager;
|
| 30206 |
amit.gupta |
33 |
}
|
|
|
34 |
|
|
|
35 |
@Bean
|
| 30213 |
amit.gupta |
36 |
public CacheManager timeoutCacheManager() {
|
|
|
37 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
38 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES);
|
|
|
39 |
cacheManager.setCaffeine(caffeine);
|
|
|
40 |
return cacheManager;
|
| 30206 |
amit.gupta |
41 |
}
|
|
|
42 |
|
|
|
43 |
@Bean
|
| 30213 |
amit.gupta |
44 |
public CacheManager timeout15CacheManager() {
|
|
|
45 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
46 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(15, TimeUnit.MINUTES);
|
|
|
47 |
cacheManager.setCaffeine(caffeine);
|
|
|
48 |
return cacheManager;
|
| 22009 |
ashik.ali |
49 |
}
|
| 23716 |
amit.gupta |
50 |
|
| 22009 |
ashik.ali |
51 |
@Bean
|
| 30213 |
amit.gupta |
52 |
public CacheManager oneDayCacheManager() {
|
|
|
53 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
54 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(6, TimeUnit.HOURS);
|
|
|
55 |
cacheManager.setCaffeine(caffeine);
|
|
|
56 |
return cacheManager;
|
| 22009 |
ashik.ali |
57 |
}
|
| 30206 |
amit.gupta |
58 |
|
| 30213 |
amit.gupta |
59 |
|
| 29854 |
amit.gupta |
60 |
@Bean
|
| 30213 |
amit.gupta |
61 |
public CacheManager twoMintimeoutCacheManager() {
|
|
|
62 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
63 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(2, TimeUnit.MINUTES);
|
|
|
64 |
cacheManager.setCaffeine(caffeine);
|
|
|
65 |
return cacheManager;
|
| 29854 |
amit.gupta |
66 |
}
|
| 23716 |
amit.gupta |
67 |
|
| 23405 |
amit.gupta |
68 |
@Bean
|
| 34715 |
ranu |
69 |
public CacheManager fiveMintimeoutCacheManager() {
|
|
|
70 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
71 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES);
|
|
|
72 |
cacheManager.setCaffeine(caffeine);
|
|
|
73 |
return cacheManager;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
@Bean
|
| 30213 |
amit.gupta |
77 |
public CacheManager thirtyMinsTimeOutCacheManager() {
|
|
|
78 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
79 |
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES);
|
|
|
80 |
cacheManager.setCaffeine(caffeine);
|
|
|
81 |
return cacheManager;
|
| 30289 |
amit.gupta |
82 |
|
|
|
83 |
|
| 23405 |
amit.gupta |
84 |
}
|
| 22009 |
ashik.ali |
85 |
|
| 30206 |
amit.gupta |
86 |
|
| 30289 |
amit.gupta |
87 |
@Bean
|
| 30213 |
amit.gupta |
88 |
JedisConnectionFactory jedisConnectionFactory() {
|
|
|
89 |
return new JedisConnectionFactory();
|
|
|
90 |
}
|
|
|
91 |
|
| 22708 |
amit.gupta |
92 |
@Bean
|
| 30213 |
amit.gupta |
93 |
public RedisCacheConfiguration cacheConfiguration() {
|
|
|
94 |
return RedisCacheConfiguration.defaultCacheConfig()
|
|
|
95 |
.entryTtl(Duration.ofMinutes(120))
|
|
|
96 |
.disableCachingNullValues()
|
|
|
97 |
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(
|
| 30289 |
amit.gupta |
98 |
new GenericJackson2JsonRedisSerializer(
|
|
|
99 |
this.getObjectMapper().enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY))));
|
| 22708 |
amit.gupta |
100 |
}
|
|
|
101 |
|
| 30289 |
amit.gupta |
102 |
private ObjectMapper getObjectMapper() {
|
|
|
103 |
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
|
|
|
104 |
return mapper;
|
|
|
105 |
}
|
|
|
106 |
|
| 23405 |
amit.gupta |
107 |
@Bean
|
| 35171 |
amit |
108 |
public CacheManager redisShortCacheManager() {
|
|
|
109 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
| 35176 |
amit |
110 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofMinutes(60)))
|
| 35171 |
amit |
111 |
.build();
|
|
|
112 |
}
|
|
|
113 |
@Bean
|
| 30289 |
amit.gupta |
114 |
public CacheManager redisCacheManager() {
|
| 34828 |
amit |
115 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
| 33635 |
amit.gupta |
116 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofHours(6)))
|
| 34828 |
amit |
117 |
.build();
|
| 30289 |
amit.gupta |
118 |
}
|
| 33323 |
amit.gupta |
119 |
@Bean
|
| 35388 |
amit |
120 |
public CacheManager redisOneDayCacheManager() {
|
|
|
121 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
|
|
122 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofDays(1)))
|
|
|
123 |
.build();
|
|
|
124 |
}
|
|
|
125 |
@Bean
|
| 33323 |
amit.gupta |
126 |
public CacheManager redisFortnightlyCacheManage() {
|
| 34828 |
amit |
127 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
| 33323 |
amit.gupta |
128 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ofDays(15).minusMinutes(5)))
|
| 34828 |
amit |
129 |
.build();
|
| 33323 |
amit.gupta |
130 |
}
|
| 23405 |
amit.gupta |
131 |
|
| 30305 |
amit.gupta |
132 |
@Bean
|
|
|
133 |
public CacheManager redisEternalCacheManager() {
|
| 34828 |
amit |
134 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
| 30305 |
amit.gupta |
135 |
.cacheDefaults(cacheConfiguration().entryTtl(Duration.ZERO))
|
| 34828 |
amit |
136 |
.build();
|
| 30305 |
amit.gupta |
137 |
}
|
|
|
138 |
|
| 22009 |
ashik.ali |
139 |
}
|