| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
3 |
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
| 4 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 5 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
5 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 6 |
import com.github.benmanes.caffeine.cache.Caffeine;
|
6 |
import com.github.benmanes.caffeine.cache.Caffeine;
|
| - |
|
7 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
8 |
import org.apache.logging.log4j.Logger;
|
| - |
|
9 |
import org.springframework.cache.Cache;
|
| 7 |
import org.springframework.cache.CacheManager;
|
10 |
import org.springframework.cache.CacheManager;
|
| 8 |
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
11 |
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
| 9 |
import org.springframework.cache.annotation.EnableCaching;
|
12 |
import org.springframework.cache.annotation.EnableCaching;
|
| 10 |
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
13 |
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
| - |
|
14 |
import org.springframework.cache.interceptor.CacheErrorHandler;
|
| 11 |
import org.springframework.context.annotation.Bean;
|
15 |
import org.springframework.context.annotation.Bean;
|
| 12 |
import org.springframework.context.annotation.Configuration;
|
16 |
import org.springframework.context.annotation.Configuration;
|
| 13 |
import org.springframework.context.annotation.PropertySource;
|
17 |
import org.springframework.context.annotation.PropertySource;
|
| 14 |
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
18 |
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
| 15 |
import org.springframework.data.redis.cache.RedisCacheManager;
|
19 |
import org.springframework.data.redis.cache.RedisCacheManager;
|
| Line 28... |
Line 32... |
| 28 |
@Configuration
|
32 |
@Configuration
|
| 29 |
@EnableCaching
|
33 |
@EnableCaching
|
| 30 |
@PropertySource("classpath:application.properties")
|
34 |
@PropertySource("classpath:application.properties")
|
| 31 |
public class CacheConfig extends CachingConfigurerSupport {
|
35 |
public class CacheConfig extends CachingConfigurerSupport {
|
| 32 |
|
36 |
|
| - |
|
37 |
private static final Logger LOGGER = LogManager.getLogger(CacheConfig.class);
|
| - |
|
38 |
|
| - |
|
39 |
@Override
|
| - |
|
40 |
public CacheErrorHandler errorHandler() {
|
| - |
|
41 |
return new CacheErrorHandler() {
|
| - |
|
42 |
@Override
|
| - |
|
43 |
public void handleCacheGetError(RuntimeException e, Cache cache, Object key) {
|
| - |
|
44 |
LOGGER.warn("Cache get error on [{}] key [{}]: {}", cache.getName(), key, e.getMessage());
|
| - |
|
45 |
cache.evict(key);
|
| - |
|
46 |
}
|
| - |
|
47 |
|
| - |
|
48 |
@Override
|
| - |
|
49 |
public void handleCachePutError(RuntimeException e, Cache cache, Object key, Object value) {
|
| - |
|
50 |
LOGGER.warn("Cache put error on [{}] key [{}]: {}", cache.getName(), key, e.getMessage());
|
| - |
|
51 |
}
|
| - |
|
52 |
|
| - |
|
53 |
@Override
|
| - |
|
54 |
public void handleCacheEvictError(RuntimeException e, Cache cache, Object key) {
|
| - |
|
55 |
LOGGER.warn("Cache evict error on [{}] key [{}]: {}", cache.getName(), key, e.getMessage());
|
| - |
|
56 |
}
|
| - |
|
57 |
|
| - |
|
58 |
@Override
|
| - |
|
59 |
public void handleCacheClearError(RuntimeException e, Cache cache) {
|
| - |
|
60 |
LOGGER.warn("Cache clear error on [{}]: {}", cache.getName(), e.getMessage());
|
| - |
|
61 |
}
|
| - |
|
62 |
};
|
| - |
|
63 |
}
|
| - |
|
64 |
|
| 33 |
@Override
|
65 |
@Override
|
| 34 |
@Bean
|
66 |
@Bean
|
| 35 |
public CacheManager cacheManager() {
|
67 |
public CacheManager cacheManager() {
|
| 36 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
68 |
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
| 37 |
return cacheManager;
|
69 |
return cacheManager;
|
| Line 146... |
Line 178... |
| 146 |
RedisCacheConfiguration defaultJsonConfig = cacheConfiguration().entryTtl(Duration.ofHours(6));
|
178 |
RedisCacheConfiguration defaultJsonConfig = cacheConfiguration().entryTtl(Duration.ofHours(6));
|
| 147 |
RedisCacheConfiguration jdkConfig = jdkCacheConfiguration(Duration.ofHours(6));
|
179 |
RedisCacheConfiguration jdkConfig = jdkCacheConfiguration(Duration.ofHours(6));
|
| 148 |
|
180 |
|
| 149 |
Map<String, RedisCacheConfiguration> cacheConfigurations = new HashMap<>();
|
181 |
Map<String, RedisCacheConfiguration> cacheConfigurations = new HashMap<>();
|
| 150 |
cacheConfigurations.put("offer.achievement", jdkCacheConfiguration(Duration.ofMinutes(30)));
|
182 |
cacheConfigurations.put("offer.achievement", jdkCacheConfiguration(Duration.ofMinutes(30)));
|
| 151 |
// Use JDK serialization for caches returning Map<Integer, ...>
|
183 |
cacheConfigurations.put("offer.definition", jdkConfig);
|
| 152 |
// to preserve Integer key types (JSON serializes map keys as String)
|
- |
|
| 153 |
cacheConfigurations.put("allOffers", jdkConfig);
|
184 |
cacheConfigurations.put("monthOfferIds", jdkConfig);
|
| 154 |
cacheConfigurations.put("offer.slabpayout", jdkConfig);
|
185 |
cacheConfigurations.put("offer.slabpayout", jdkConfig);
|
| 155 |
cacheConfigurations.put("catalog.published_yearmonth", jdkConfig);
|
186 |
cacheConfigurations.put("catalog.published_yearmonth", jdkConfig);
|
| 156 |
|
187 |
|
| 157 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
188 |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory())
|
| 158 |
.cacheDefaults(defaultJsonConfig)
|
189 |
.cacheDefaults(defaultJsonConfig)
|