remove response caching
Turn out, that caching on the client side does not play well when new data is loaded into the system.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user