package top.quantic.sentry.config;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;
import javax.inject.Inject;

@Configuration
@EnableCaching
@AutoConfigureAfter(value = {MetricsConfiguration.class})
@AutoConfigureBefore(value = {WebConfigurer.class, DatabaseConfiguration.class})
public class CacheConfiguration {

    private final Logger log = LoggerFactory.getLogger(CacheConfiguration.class);

    @Inject
    private CacheManager cacheManager;

    @PreDestroy
    public void destroy() {
        log.info("Closing Cache Manager");
    }

    @Bean
    public CacheManager cacheManager() {
        log.debug("No cache");
        cacheManager = new NoOpCacheManager();
        return cacheManager;
    }

//    @Bean
//    public CacheManager cacheManager() {
//        log.debug("Simple cache enabled");
//        SimpleCacheManager manager = new SimpleCacheManager();
//        manager.setCaches(Arrays.asList(
//            new ConcurrentMapCache("permissions"),
//            new ConcurrentMapCache("prefixes")));
//        cacheManager = manager;
//        return cacheManager;
//    }
}

@@ -30,16 +30,61 @@
 nfig;%0A%0A%0A
+import com.google.common.cache.CacheBuilder;%0A
 import o
@@ -408,20 +408,19 @@
 che.
-support.NoOp
+guava.Guava
 Cach
@@ -558,58 +558,32 @@
 java
-x.annotation.PreDestroy;%0Aimport javax.inject.Injec
+.util.concurrent.TimeUni
 t;%0A%0A
@@ -878,26 +878,23 @@
    @
-Inject%0A    private
+Bean%0A    public
  Cac
@@ -919,88 +919,54 @@
 ager
-;%0A%0A    @PreDestroy%0A    public void destroy() %7B%0A        log.info(%22Closing C
+() %7B%0A        log.debug(%22Creating Guava c
 ache 
-M
+m
 anag
@@ -979,102 +979,36 @@
     
-%7D%0A%0A
     
-@Bean%0A    public CacheManager cacheManager() %7B%0A        log.debug(%22No cache%22);%0A        c
+GuavaCacheManager guavaC
 ache
@@ -1025,12 +1025,13 @@
 new 
-NoOp
+Guava
 Cach
@@ -1054,385 +1054,107 @@
     
-return cacheManager;%0A    %7D%0A%0A//    @Bean%0A//    public CacheManager cacheManager() %7B%0A//        log.debug(%22Simple cache enabled%22);%0A//        SimpleCacheManager manager = new SimpleCacheManager();%0A//        manager.setCaches(Arrays.asList(%0A//            new ConcurrentMapCache(%22permissions%22),%0A//            new ConcurrentMapCache(%22prefixes%22)));%0A//        cacheManager = manager;%0A//
+guavaCacheManager.setCacheBuilder(CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.HOURS));%0A
     
@@ -1164,17 +1164,22 @@
  return 
-c
+guavaC
 acheMana
@@ -1187,10 +1187,8 @@
 er;%0A
-//
     

Update CacheConfiguration