update 优化 全局创建 caffeine 实例
parent
67af824af2
commit
897247075b
@ -0,0 +1,45 @@
|
||||
package org.dromara.common.redis.config;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.dromara.common.redis.manager.PlusSpringCacheManager;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 缓存配置
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableCaching
|
||||
public class CacheConfiguration {
|
||||
|
||||
/**
|
||||
* caffeine 本地缓存处理器
|
||||
*/
|
||||
@Bean
|
||||
public Cache<Object, Object> caffeine() {
|
||||
return Caffeine.newBuilder()
|
||||
// 设置最后一次写入或访问后经过固定时间过期
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
// 初始的缓存空间大小
|
||||
.initialCapacity(100)
|
||||
// 缓存的最大条数
|
||||
.maximumSize(1000)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义缓存管理器 整合spring-cache
|
||||
*/
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
return new PlusSpringCacheManager();
|
||||
}
|
||||
|
||||
}
|
@ -1 +1,2 @@
|
||||
org.dromara.common.redis.config.RedisConfiguration
|
||||
org.dromara.common.redis.config.CacheConfiguration
|
||||
|
Loading…
Reference in New Issue