Skip to content

Commit 9c560d7

Browse files
authored
Merge pull request #3450 from 1c-syntax/feature/caffeineCache
Добавлено кэширование caffeine
2 parents 17770d9 + ed237f0 commit 9c560d7

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ dependencies {
6868
api("org.springframework.boot:spring-boot-starter")
6969
api("org.springframework.boot:spring-boot-starter-websocket")
7070
api("org.springframework.boot:spring-boot-starter-cache")
71+
7172
api("info.picocli:picocli-spring-boot-starter:4.7.6")
7273

74+
// кэширование
75+
api("com.github.ben-manes.caffeine", "caffeine", "3.2.0")
76+
7377
// lsp4j core
7478
api("org.eclipse.lsp4j", "org.eclipse.lsp4j", "0.24.0")
7579
api("org.eclipse.lsp4j", "org.eclipse.lsp4j.websocket.jakarta", "0.24.0")

src/main/java/com/github/_1c_syntax/bsl/languageserver/BSLLSBinding.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.boot.WebApplicationType;
3232
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3333
import org.springframework.boot.builder.SpringApplicationBuilder;
34+
import org.springframework.cache.annotation.EnableCaching;
3435
import org.springframework.context.ConfigurableApplicationContext;
3536
import org.springframework.context.annotation.ComponentScan;
3637
import org.springframework.core.io.DefaultResourceLoader;
@@ -40,6 +41,7 @@
4041

4142
@EnableAutoConfiguration
4243
@ComponentScan("com.github._1c_syntax.bsl.languageserver")
44+
@EnableCaching(proxyTargetClass = true)
4345
public class BSLLSBinding {
4446

4547
@Getter(lazy = true, value = AccessLevel.PRIVATE)
@@ -74,17 +76,22 @@ public static ServerContext getServerContext() {
7476
}
7577

7678
private static SpringApplication createApplication() {
77-
return new SpringApplicationBuilder(BSLLSBinding.class)
79+
var app = new SpringApplicationBuilder(BSLLSBinding.class)
7880
.bannerMode(Banner.Mode.OFF)
7981
.web(WebApplicationType.NONE)
8082
.logStartupInfo(false)
8183
.resourceLoader(new DefaultResourceLoader(BSLLSBinding.class.getClassLoader()))
8284
.lazyInitialization(true)
8385
.properties(Map.of(
8486
"app.command.line.runner.enabled", "false",
85-
"app.scheduling.enabled", "false"
87+
"app.scheduling.enabled", "false",
88+
"spring.cache.caffeine.spec", "maximumSize=500,expireAfterAccess=600s",
89+
"spring.cache.cache-names", "testIds,testSources"
8690
))
8791
.build();
92+
93+
app.setRegisterShutdownHook(false);
94+
return app;
8895
}
8996

9097
private static ConfigurableApplicationContext createContext() {

src/main/java/com/github/_1c_syntax/bsl/languageserver/infrastructure/CacheConfiguration.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
*/
2222
package com.github._1c_syntax.bsl.languageserver.infrastructure;
2323

24+
import com.github.benmanes.caffeine.cache.Caffeine;
25+
import org.springframework.cache.CacheManager;
2426
import org.springframework.cache.annotation.EnableCaching;
27+
import org.springframework.cache.caffeine.CaffeineCacheManager;
28+
import org.springframework.context.annotation.Bean;
2529
import org.springframework.context.annotation.Configuration;
2630

2731
/**
@@ -30,4 +34,15 @@
3034
@Configuration
3135
@EnableCaching
3236
public class CacheConfiguration {
37+
@Bean
38+
public CacheManager cacheManager(Caffeine<Object, Object> caffeine) {
39+
var caffeineCacheManager = new CaffeineCacheManager();
40+
caffeineCacheManager.setCaffeine(caffeine);
41+
return caffeineCacheManager;
42+
}
43+
44+
@Bean
45+
public Caffeine<Object, Object> caffeineConfig() {
46+
return Caffeine.newBuilder();
47+
}
3348
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ server.port=8025
22
spring.main.banner-mode=off
33
spring.main.log-startup-info=false
44
spring.cache.cache-names=testIds,testSources
5+
spring.cache.caffeine.spec=maximumSize=500,expireAfterAccess=600s
56
logging.level.org.springframework.boot.autoconfigure.logging=INFO
67
logging.level.org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler=warn
78
logging.level.com.zaxxer.hikari=warn

0 commit comments

Comments
 (0)