1
0

feat: 增加接口缓存

This commit is contained in:
2025-10-11 16:24:28 +08:00
parent b0c2530e63
commit b9a02194e2
3 changed files with 48 additions and 0 deletions

View File

@@ -31,6 +31,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>

View File

@@ -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;
}
}