-
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.
Feat: caching for bin location address (#26)
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.drugbox.common.config; | ||
|
||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableCaching | ||
public class CacheConfig { | ||
@Bean | ||
public CacheManager cacheManager() { | ||
return new ConcurrentMapCacheManager("addresses"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.drugbox; | ||
|
||
import com.drugbox.service.MapService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class CacheTest { | ||
|
||
@Autowired | ||
MapService mapService; | ||
|
||
@Autowired | ||
private CacheManager cacheManager; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
cacheManager.getCache("addresses").clear(); | ||
mapService.saveSeoulDrugBinLocations(); | ||
} | ||
|
||
@Test | ||
public void 서울_주소_캐싱_테스트(){ | ||
long start = System.currentTimeMillis(); | ||
mapService.getSeoulDrugBinLocations(); | ||
long executionTimeWithoutCache = System.currentTimeMillis() - start; | ||
System.out.println("Execution time without cache: " + executionTimeWithoutCache + "ms"); | ||
|
||
start = System.currentTimeMillis(); | ||
mapService.getSeoulDrugBinLocations(); | ||
long executionTimeWithCache = System.currentTimeMillis() - start; | ||
System.out.println("Execution time with cache: " + executionTimeWithCache + "ms"); | ||
|
||
assertTrue("Execution time with cache should be less than without cache", | ||
executionTimeWithoutCache > executionTimeWithCache); | ||
} | ||
} |