io.github.dengchen2020.cache.caffeine.CaffeineCacheSyncAutoConfiguration Maven / Gradle / Ivy
package io.github.dengchen2020.cache.caffeine;
import io.github.dengchen2020.cache.listener.CacheSyncMessageListener;
import io.github.dengchen2020.cache.model.CacheSyncParam;
import io.github.dengchen2020.core.utils.ProtostuffUtils;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.MessageListener;
/**
* Caffeine缓存同步自动配置
* 依赖redis的发布订阅,需引入
* {@code
*
* org.springframework.boot
* spring-boot-starter-data-redis
* latest
* }
*
* @author dengchen
* @since 2024/7/3
*/
@ConditionalOnClass(MessageListener.class)
@ConditionalOnBean(CaffeineCacheManager.class)
@AutoConfigureAfter(CaffeineCacheAutoConfiguration.class)
@Configuration(proxyBeanMethods = false)
public class CaffeineCacheSyncAutoConfiguration {
@Bean
public CacheSyncMessageListener cacheSyncMessageListener(CacheManager cacheManager) {
ProtostuffUtils.STRATEGY.registerPojo(CacheSyncParam.class);
return new CacheSyncMessageListener(cacheManager);
}
}