Skip to content

Commit

Permalink
Cache scrape endpoint to reduce calls
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Jul 17, 2023
1 parent 8fdbe8c commit 6425e58
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/jasper/web/rest/ScrapeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ void scrapeFeed(
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(ref = "https://opensource.zalando.com/problem/schema.yaml#/Problem"))),
})
@GetMapping("web")
RefDto scrapeWebpage(@RequestParam @Length(max = URL_LEN) @URL String url) throws IOException, URISyntaxException {
return scrapeService.webpage(url);
ResponseEntity<RefDto> scrapeWebpage(@RequestParam @Length(max = URL_LEN) @URL String url) throws IOException, URISyntaxException {
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(100, TimeUnit.DAYS).cachePublic())
.body(scrapeService.webpage(url));
}

@ApiResponses({
Expand All @@ -89,7 +91,7 @@ ResponseEntity<byte[]> fetch(@RequestParam @Length(max = URL_LEN) String url) {
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(ref = "https://opensource.zalando.com/problem/schema.yaml#/Problem"))),
})
@GetMapping("rss")
ResponseEntity<String> rss(@RequestParam @Length(max = URL_LEN) String url) throws URISyntaxException, IOException {
ResponseEntity<String> rss(@RequestParam @Length(max = URL_LEN) String url) {
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(100, TimeUnit.DAYS).cachePrivate())
.body(scrapeService.rss(url));
Expand Down

0 comments on commit 6425e58

Please sign in to comment.