feat: 增加接口缓存
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.lanyuanxiaoyao.leopard.server.configuration;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* 缓存提供
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2023-04-23
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class CacheProvider {
|
||||
@Primary
|
||||
@Bean("short-cache")
|
||||
public CacheManager normalCache() {
|
||||
CaffeineCacheManager manager = new CaffeineCacheManager();
|
||||
manager.setCaffeine(Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES));
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Bean("long-cache")
|
||||
public CacheManager longCache() {
|
||||
CaffeineCacheManager manager = new CaffeineCacheManager();
|
||||
manager.setCaffeine(Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS));
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user