-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[refactor] 지역 전체 조회에 대한 로컬 캐시 적용 (#537)
- Loading branch information
Showing
6 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
backend/src/main/java/dev/tripdraw/area/application/AreaServiceFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/dev/tripdraw/common/cache/CacheType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dev.tripdraw.common.cache; | ||
|
||
public enum CacheType { | ||
|
||
AREAS("areas", 1); | ||
|
||
private final String cacheName; | ||
private final int maximumSize; | ||
|
||
CacheType(String cacheName, int maximumSize) { | ||
this.cacheName = cacheName; | ||
this.maximumSize = maximumSize; | ||
} | ||
|
||
public String cacheName() { | ||
return cacheName; | ||
} | ||
|
||
public int maximumSize() { | ||
return maximumSize; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/dev/tripdraw/common/config/CacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dev.tripdraw.common.config; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import dev.tripdraw.common.cache.CacheType; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.cache.caffeine.CaffeineCache; | ||
import org.springframework.cache.support.SimpleCacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@EnableCaching | ||
@Configuration | ||
public class CacheConfig { | ||
|
||
@Bean | ||
public CacheManager cacheManager() { | ||
SimpleCacheManager cacheManager = new SimpleCacheManager(); | ||
cacheManager.setCaches(caches()); | ||
return cacheManager; | ||
} | ||
|
||
private List<CaffeineCache> caches() { | ||
return Arrays.stream(CacheType.values()) | ||
.map(cacheType -> new CaffeineCache(cacheType.cacheName(), cache(cacheType))) | ||
.toList(); | ||
} | ||
|
||
private Cache<Object, Object> cache(CacheType cacheType) { | ||
return Caffeine.newBuilder() | ||
.maximumSize(cacheType.maximumSize()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters