All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ideaaedi.extspringcache.ExtCacheConfiguration Maven / Gradle / Ivy

The newest version!
package com.ideaaedi.extspringcache;


import com.ideaaedi.extspringcache.caffeine.ExtCaffeineCacheInitParser;
import com.ideaaedi.extspringcache.event.EnableExtSpringCacheEvent;
import com.ideaaedi.extspringcache.event.listener.EnableExtSpringCacheListener;
import com.ideaaedi.extspringcache.manager.ExtCacheManager;
import com.ideaaedi.extspringcache.parser.ExtCacheChecker;
import com.ideaaedi.extspringcache.properties.ExtSpringCacheProperties;
import com.ideaaedi.extspringcache.provider.ExtCaffeineCacheManagerProvider;
import com.ideaaedi.extspringcache.provider.ExtRedisCacheManagerProvider;
import com.ideaaedi.extspringcache.provider.ExtRedisCaffeineCacheManagerProvider;
import com.ideaaedi.extspringcache.redis.ExtRedisCacheInitParser;
import com.ideaaedi.extspringcache.redis_caffeine.ExtRedisCaffeineCacheInitParser;
import com.ideaaedi.extspringcache.support.ExtCacheAroundHandlerAdvice;
import org.springframework.beans.BeansException;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;

/**
 * config for ext-cache
 * 

* 我们希望: @ExtCacheable 走 ExtCacheManager, 而原来的@Cacheable,仍然走原来默认的CacheManager, 所以这里@AutoConfigureAfter * (CacheAutoConfiguration.class) * P.S. 默认的cacheManager * 是哪个可见{@link org.springframework.cache.interceptor.CacheAspectSupport#afterSingletonsInstantiated()} * * @author JustryDeng * @since 2020/11/4 12:56:08 */ @AutoConfigureAfter(CacheAutoConfiguration.class) @EnableConfigurationProperties(ExtSpringCacheProperties.class) public class ExtCacheConfiguration implements ApplicationContextAware { @Bean(ExtRedisCaffeineCacheManagerProvider.BEAN_NAME) public ExtRedisCaffeineCacheManagerProvider extRedisCaffeineCacheManagerProvider() { return new ExtRedisCaffeineCacheManagerProvider(); } @Bean(ExtRedisCaffeineCacheInitParser.BEAN_NAME) public ExtRedisCaffeineCacheInitParser extRedisCaffeineCacheInitParser() { return new ExtRedisCaffeineCacheInitParser(); } @Bean(ExtCaffeineCacheManagerProvider.BEAN_NAME) public ExtCaffeineCacheManagerProvider extCaffeineCacheManagerProvider() { return new ExtCaffeineCacheManagerProvider(); } @Bean(ExtRedisCacheManagerProvider.BEAN_NAME) public ExtRedisCacheManagerProvider extRedisCacheManagerProvider() { return new ExtRedisCacheManagerProvider(); } @Bean(ExtCacheChecker.BEAN_NAME) public ExtCacheChecker extCacheChecker() { return new ExtCacheChecker(); } @Bean(ExtCacheAroundHandlerAdvice.BEAN_NAME) public ExtCacheAroundHandlerAdvice extCacheAroundHandler() { return new ExtCacheAroundHandlerAdvice(); } @Bean(EnableExtSpringCacheListener.BEAN_NAME) public EnableExtSpringCacheListener enableExtSpringCacheListener(ExtSpringCacheProperties extSpringCacheProperties) { return new EnableExtSpringCacheListener(extSpringCacheProperties); } @Bean(ExtRedisCacheInitParser.BEAN_NAME) public ExtRedisCacheInitParser extRedisCacheInitParser() { return new ExtRedisCacheInitParser(); } @Bean(ExtCaffeineCacheInitParser.BEAN_NAME) public ExtCaffeineCacheInitParser extCaffeineCacheInitParser() { return new ExtCaffeineCacheInitParser(); } @DependsOn(ExtRedisCacheInitParser.BEAN_NAME) @Bean(name = ExtCacheManager.BEAN_NAME, autowireCandidate = false) public ExtCacheManager extCacheManager() { return new ExtCacheManager(); } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { applicationContext.publishEvent(new EnableExtSpringCacheEvent(System.currentTimeMillis())); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy