package com.jin.data.cache;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.SimpleCacheResolver;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.Bean;

@EnableConfigurationProperties(CacheProperties.class)
public abstract class CacheConfig extends CachingConfigurerSupport {
	private static final Logger logger = LoggerFactory.getLogger(CacheConfig.class);
	
	@Autowired
	CacheProperties cacheProperties;
	
	public abstract CacheManager cacheManager();
	
	public CacheManager noOpCacheManager(){
		
		return new NoOpCacheManager();
		
	}
	
	@Bean
	public CacheResolver cacheResolver() {
		CacheResolver cacheResolver;
	
		logger.info("Current Cache Type is: " + cacheProperties.getType().name());
		if (cacheProperties.getType().name().equals("NONE")){
			cacheResolver = new SimpleCacheResolver(noOpCacheManager());
		} else {
			cacheResolver = new SimpleCacheResolver(cacheManager());
		}
		return cacheResolver;
	}
}
@@ -22,16 +22,49 @@
 cache;%0A%0A
+import java.time.LocalDateTime;%0A%0A
 import o
@@ -76,24 +76,24 @@
 f4j.Logger;%0A
-
 import org.s
@@ -318,32 +318,72 @@
 tionProperties;%0A
+import org.springframework.cache.Cache;%0A
 import org.sprin
@@ -483,16 +483,80 @@
 upport;%0A
+import org.springframework.cache.interceptor.CacheErrorHandler;%0A
 import o
@@ -990,18 +990,17 @@
 class);%0A
-%09
 %0A
+
 %09@Autowi
@@ -1037,18 +1037,17 @@
 erties;%0A
-%09
 %0A
+
 %09public 
@@ -1084,17 +1084,16 @@
 ager();%0A
-%09
 %0A%09public
@@ -1124,20 +1124,19 @@
 anager()
+ 
 %7B%0A
-%09%09
 %0A%09%09retur
@@ -1165,16 +1165,13 @@
 ();%0A
-%09%09
 %0A
+
 %09%7D%0A
-%09
 %0A
+
 %09@Be
@@ -1248,10 +1248,9 @@
 er;%0A
-%09
 %0A
+
 %09%09lo
@@ -1376,16 +1376,17 @@
 %22NONE%22))
+ 
 %7B%0A%09%09%09cac
@@ -1542,12 +1542,1245 @@
 solver;%0A
-
 %09%7D%0A
+%0A%09@Override%0A%09public CacheErrorHandler errorHandler() %7B%0A%09%09return new CacheErrorHandler() %7B%0A%0A%09%09%09@Override%0A%09%09%09public void handleCacheClearError(RuntimeException ex, Cache cache) %7B%0A%09%09%09%09logger.warn(%0A%09%09%09%09%09%09%22Exception occured when fetching an item from Redis.Time : %7B%7D , Cache : %7B%7D, Exception : %22,%0A%09%09%09%09%09%09LocalDateTime.now(), cache.getName(), ex);%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void handleCacheEvictError(RuntimeException ex, Cache cache, Object key) %7B%0A%09%09%09%09logger.warn(%0A%09%09%09%09%09%09%22Exception occured when fetching an item from Redis.Time : %7B%7D , Key : %7B%7D , Cache : %7B%7D, Exception : %22,%0A%09%09%09%09%09%09LocalDateTime.now(), key, cache.getName(), ex);%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void handleCacheGetError(RuntimeException ex, Cache cache, Object key) %7B%0A%09%09%09%09logger.warn(%0A%09%09%09%09%09%09%22Exception occured when fetching an item from Redis.Time : %7B%7D , Key : %7B%7D , Cache : %7B%7D, Exception : %22,%0A%09%09%09%09%09%09LocalDateTime.now(), key, cache.getName(), ex);%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void handleCachePutError(RuntimeException ex, Cache cache, Object arg1, Object arg2) %7B%0A%09%09%09%09logger.warn(%0A%09%09%09%09%09%09%22Exception occured when fetching an item from Redis.Time : %7B%7D , arg1 : %7B%7D , arg2 : %7B%7D , Cache : %7B%7D, Exception : %22,%0A%09%09%09%09%09%09LocalDateTime.now(), arg1, arg2, cache.getName(), ex);%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%0A
 %7D

Add the cache error handler to bypass redis exception.