From 26c6e252da5bdfa032c7718d5a29607176d13898 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 13 Aug 2018 09:37:30 -0400 Subject: [PATCH] world controller: fix caching, move to scheduled method Guava memorize will block threads waiting for a new result --- .../http/service/worlds/WorldController.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java b/http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java index 893ee6278d..7dba1bc1dd 100644 --- a/http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java +++ b/http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java @@ -24,15 +24,14 @@ */ package net.runelite.http.service.worlds; -import com.google.common.base.Suppliers; import java.io.IOException; import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; import lombok.extern.slf4j.Slf4j; import net.runelite.http.api.worlds.WorldResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.CacheControl; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -44,24 +43,19 @@ public class WorldController @Autowired private WorldsService worldsService; - private final Supplier worlds = Suppliers.memoizeWithExpiration(() -> - { - try - { - return worldsService.getWorlds(); - } - catch (IOException ex) - { - log.warn(null, ex); - throw new RuntimeException(ex); - } - }, 10, TimeUnit.MINUTES); + private WorldResult worldResult; @RequestMapping public ResponseEntity listWorlds() throws IOException { return ResponseEntity.ok() .cacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES).cachePublic()) - .body(worldsService.getWorlds()); + .body(worldResult); + } + + @Scheduled(fixedDelay = 60_000L) + public void refreshWorlds() throws IOException + { + worldResult = worldsService.getWorlds(); } }