From 47e32bb6b11c054cbd81806a96762c1434c22558 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 10 May 2018 17:52:13 +0200 Subject: [PATCH] remove response caching Turn out, that caching on the client side does not play well when new data is loaded into the system. --- .../main/java/org/lucares/pdbui/CleanupThread.java | 7 +++---- .../main/java/org/lucares/pdbui/PdbController.java | 8 +------- .../src/main/java/org/lucares/pdbui/PropertyKeys.java | 10 ---------- .../main/java/org/lucares/pdbui/WebConfiguration.java | 11 ++--------- pdb-ui/src/main/resources/application.properties | 2 -- 5 files changed, 6 insertions(+), 32 deletions(-) diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/CleanupThread.java b/pdb-ui/src/main/java/org/lucares/pdbui/CleanupThread.java index 3959ae8..1e3463e 100644 --- a/pdb-ui/src/main/java/org/lucares/pdbui/CleanupThread.java +++ b/pdb-ui/src/main/java/org/lucares/pdbui/CleanupThread.java @@ -70,15 +70,14 @@ public class CleanupThread implements DisposableBean, PropertyKeys { } private final ScheduledExecutorService scheduledThreadPool; + private static final int CACHE_DURATION_IN_SECONDS = 24 * 3600; @Autowired - public CleanupThread(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir, - @Value("${" + CACHE_IMAGES_DURATION_SECONDS + ":" + CACHE_IMAGES_DURATION_SECONDS_DEFAULT - + "}") final int cacheDurationInSeconds) { + public CleanupThread(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir) { scheduledThreadPool = Executors.newScheduledThreadPool(1, new CustomizableThreadFactory("cleanup-")); final Path outputPath = Paths.get(outputDir); - scheduledThreadPool.scheduleWithFixedDelay(new RemoveTempFiles(outputPath, cacheDurationInSeconds), 1, 5, + scheduledThreadPool.scheduleWithFixedDelay(new RemoveTempFiles(outputPath, CACHE_DURATION_IN_SECONDS), 1, 5, TimeUnit.MINUTES); } diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java b/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java index c42a9d3..954f08c 100644 --- a/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java +++ b/pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java @@ -36,7 +36,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.http.CacheControl; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -69,9 +68,6 @@ public class PdbController implements HardcodedValues, PropertyKeys { @Value("${" + PRODUCTION_MODE + ":true}") private boolean modeProduction; - @Value("${" + CACHE_IMAGES_DURATION_SECONDS + ":" + CACHE_IMAGES_DURATION_SECONDS_DEFAULT + "}") - private int cacheDurationInSeconds; - public PdbController(final PerformanceDb db, final Plotter plotter) { this.db = db; this.plotter = plotter; @@ -134,9 +130,7 @@ public class PdbController implements HardcodedValues, PropertyKeys { final PlotResponseStats stats = PlotResponseStats.fromDataSeries(result.getDataSeries()); final PlotResponse plotResponse = new PlotResponse(stats, imageUrl, thumbnailUrl); - final CacheControl cacheControl = CacheControl.maxAge(cacheDurationInSeconds, TimeUnit.SECONDS); - - return ResponseEntity.ok().cacheControl(cacheControl).body(plotResponse); + return ResponseEntity.ok().body(plotResponse); } catch (final NoDataPointsException e) { throw new NotFoundException(e); } finally { diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/PropertyKeys.java b/pdb-ui/src/main/java/org/lucares/pdbui/PropertyKeys.java index 0cfdfc6..e4d2ea4 100644 --- a/pdb-ui/src/main/java/org/lucares/pdbui/PropertyKeys.java +++ b/pdb-ui/src/main/java/org/lucares/pdbui/PropertyKeys.java @@ -12,16 +12,6 @@ public interface PropertyKeys { */ String TMP_DIR = "path.tmp"; - /** - * The number of seconds generated images shall be cached. - */ - String CACHE_IMAGES_DURATION_SECONDS = "cache.images.duration.seconds"; - - /** - * Default value for {@link PropertyKeys#CACHE_IMAGES_DURATION_SECONDS} - */ - String CACHE_IMAGES_DURATION_SECONDS_DEFAULT = "3600"; - /** * Indicates whether or not this instance is running in production. This * property is used to switch Vue.js into production or development mode. diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/WebConfiguration.java b/pdb-ui/src/main/java/org/lucares/pdbui/WebConfiguration.java index 7bc7568..89dabd2 100644 --- a/pdb-ui/src/main/java/org/lucares/pdbui/WebConfiguration.java +++ b/pdb-ui/src/main/java/org/lucares/pdbui/WebConfiguration.java @@ -1,11 +1,9 @@ package org.lucares.pdbui; import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -import org.springframework.http.CacheControl; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -13,13 +11,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; public class WebConfiguration implements WebMvcConfigurer, HardcodedValues, PropertyKeys { private final String outputDir; - private final int cacheDurationInSeconds; - public WebConfiguration(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir, - @Value("${" + CACHE_IMAGES_DURATION_SECONDS + ":" + CACHE_IMAGES_DURATION_SECONDS_DEFAULT - + "}") final int cacheDurationInSeconds) { + public WebConfiguration(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir) { this.outputDir = outputDir; - this.cacheDurationInSeconds = cacheDurationInSeconds; } @Override @@ -28,7 +22,6 @@ public class WebConfiguration implements WebMvcConfigurer, HardcodedValues, Prop final String pathPattern = "/" + WEB_IMAGE_OUTPUT_PATH + "/**"; final String resourceLocation = "file:" + Paths.get(outputDir).toAbsolutePath() + "/"; - final CacheControl cacheControl = CacheControl.maxAge(cacheDurationInSeconds, TimeUnit.SECONDS); - registry.addResourceHandler(pathPattern).addResourceLocations(resourceLocation).setCacheControl(cacheControl); + registry.addResourceHandler(pathPattern).addResourceLocations(resourceLocation); } } diff --git a/pdb-ui/src/main/resources/application.properties b/pdb-ui/src/main/resources/application.properties index ac2c504..4328d87 100644 --- a/pdb-ui/src/main/resources/application.properties +++ b/pdb-ui/src/main/resources/application.properties @@ -4,6 +4,4 @@ db.base=${base.dir}/db path.tmp=${base.dir}/tmp path.output=${base.dir}/out -cache.images.duration.seconds=3600 - logging.config=classpath:log4j2.xml