This repository was archived by the owner on Dec 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
src/main/java/com/cf/cfteam/config Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ dependencies {
4444 implementation ' io.jsonwebtoken:jjwt-impl:0.12.6'
4545 implementation ' io.jsonwebtoken:jjwt-jackson:0.12.6'
4646
47+ // cache
48+ implementation ' com.github.ben-manes.caffeine:caffeine:3.1.8'
49+
4750 // test
4851 testImplementation ' org.springframework.boot:spring-boot-starter-test'
4952 testImplementation ' org.testcontainers:junit-jupiter:1.20.1'
Original file line number Diff line number Diff line change 11package com .cf .cfteam .config ;
22
33import com .cf .cfteam .services .security .MyUserDetailsService ;
4+ import com .cf .cfteam .utils .codeforces .mappers .GroupMapper ;
45import lombok .RequiredArgsConstructor ;
56import org .springframework .beans .factory .annotation .Value ;
67import org .springframework .context .annotation .Bean ;
Original file line number Diff line number Diff line change 1+ package com .cf .cfteam .config ;
2+
3+ import com .cf .cfteam .services .client .CodeforcesClient ;
4+ import com .github .benmanes .caffeine .cache .Cache ;
5+ import com .github .benmanes .caffeine .cache .CacheLoader ;
6+ import com .github .benmanes .caffeine .cache .Caffeine ;
7+ import com .github .benmanes .caffeine .cache .LoadingCache ;
8+ import lombok .RequiredArgsConstructor ;
9+ import org .springframework .context .annotation .Bean ;
10+ import org .springframework .context .annotation .Configuration ;
11+
12+ import java .util .concurrent .TimeUnit ;
13+
14+ @ Configuration
15+ @ RequiredArgsConstructor
16+ public class CacheConfig {
17+
18+ private final CodeforcesClient codeforcesClient ;
19+
20+ @ Bean
21+ public LoadingCache <String , Double > ratingCache () {
22+ return Caffeine .newBuilder ()
23+ .expireAfterWrite (1 , TimeUnit .HOURS )
24+ .maximumSize (1000 )
25+ .build (codeforcesClient ::fetchRatingFromApi );
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments