yuzurss

Feed aggregator microservice based on Spring
git clone https://git.neuralcrash.com/yuzurss.git
Log | Files | Refs | README | LICENSE

commit bb9f30f59179a02760b27f6279c07af3e6ae0949
parent 5e3bd9f3c0b588b40cbad332f6b85373d8c69bcc
Author: Kebigon <git@kebigon.xyz>
Date:   Sat, 15 Dec 2018 21:32:00 +0900

Add caching of FeedClient
Diffstat:
Mpom.xml | 9+++++++++
Msrc/main/java/fr/lrgn/yuzurss/FeedClient.java | 4+++-
Msrc/main/java/fr/lrgn/yuzurss/FeedController.java | 1+
Msrc/main/java/fr/lrgn/yuzurss/YuzuRssApplication.java | 2++
Msrc/main/resources/application.properties | 6++++--
5 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml @@ -26,10 +26,19 @@ <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-cache</artifactId> + </dependency> + + <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20180813</version> </dependency> + <dependency> + <groupId>com.github.ben-manes.caffeine</groupId> + <artifactId>caffeine</artifactId> + </dependency> <dependency> <groupId>org.springframework.boot</groupId> diff --git a/src/main/java/fr/lrgn/yuzurss/FeedClient.java b/src/main/java/fr/lrgn/yuzurss/FeedClient.java @@ -12,6 +12,7 @@ import org.json.JSONObject; import org.json.XML; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; @@ -30,6 +31,7 @@ public class FeedClient private final Logger log = LoggerFactory.getLogger(getClass()); + @Cacheable("feeds") public Flux<FeedEntry> getFeed(URI uri) { final WebClient client = WebClient.create(); @@ -50,7 +52,7 @@ public class FeedClient log.info("Exception while parsing {}", uri, e); return Flux.empty(); } - }); + }).cache(); } private static boolean isAtom(JSONObject root) diff --git a/src/main/java/fr/lrgn/yuzurss/FeedController.java b/src/main/java/fr/lrgn/yuzurss/FeedController.java @@ -3,6 +3,7 @@ package fr.lrgn.yuzurss; import java.net.URI; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/fr/lrgn/yuzurss/YuzuRssApplication.java b/src/main/java/fr/lrgn/yuzurss/YuzuRssApplication.java @@ -2,8 +2,10 @@ package fr.lrgn.yuzurss; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; @SpringBootApplication +@EnableCaching public class YuzuRssApplication { public static void main(String[] args) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties @@ -1 +1,3 @@ -server.port=8091 -\ No newline at end of file +server.port=8091 +spring.cache.cache-names=feeds +spring.cache.caffeine.spec=maximumSize=100,expireAfterAccess=10m +\ No newline at end of file