Skip to content

Commit

Permalink
[FEAT] cache external api
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Nov 27, 2023
1 parent e560788 commit b47b648
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import jakarta.validation.Valid;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -21,12 +22,14 @@ public PathController(PathService pathService) {
}

@PostMapping("/search/car")
@Cacheable(value = "carPath", key = "{#request}", cacheManager = "cacheManager", unless = "result.body.code != 0")
public ResponseEntity<SearchCarPathResponse> searchCarPath(
@RequestBody @Valid SearchCarPathRequest request) {
return ResponseEntity.ok(pathService.searchCarPath(request));
}

@PostMapping("/search/ped")
@Cacheable(value = "pedPath", key = "{#request}", cacheManager = "cacheManager", unless = "result.body.features.size() <= 0")
public ResponseEntity<SearchPedPathResponse> searchPedPath(
@RequestBody @Valid SearchPedPathRequest request) {
return ResponseEntity.ok(pathService.searchPedPath(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import lombok.RequiredArgsConstructor;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -19,6 +20,7 @@ public class PlaceController {
private final PlaceService placeService;

@GetMapping("surround")
@Cacheable(value = "surroundPlace", key = "{#surroundPlaceRequest}", cacheManager = "cacheManager", unless = "result.body.results.size() <= 0")
public ResponseEntity<PlaceResponse> searchSurroundPlace(
@ModelAttribute final SurroundPlaceRequest surroundPlaceRequest) {
return ResponseEntity.ok(placeService.searchSurroundPlace(surroundPlaceRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import lombok.RequiredArgsConstructor;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -22,6 +23,7 @@ public class PlanController {
private final PlanService planService;

@GetMapping("search/destination")
@Cacheable(value = "planDestination", key = "{#request}", cacheManager = "cacheManager", unless = "result.body.results.size() <= 0")
public ResponseEntity<PlanDestinationResponse> searchPlanDestination(
@ModelAttribute final SearchDestinationRequest request) {
return ResponseEntity.ok(planService.searchPlanDestination(request));
Expand Down

0 comments on commit b47b648

Please sign in to comment.