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 final ScheduledExecutorService scheduledThreadPool;
|
||||||
|
private static final int CACHE_DURATION_IN_SECONDS = 24 * 3600;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CleanupThread(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir,
|
public CleanupThread(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir) {
|
||||||
@Value("${" + CACHE_IMAGES_DURATION_SECONDS + ":" + CACHE_IMAGES_DURATION_SECONDS_DEFAULT
|
|
||||||
+ "}") final int cacheDurationInSeconds) {
|
|
||||||
scheduledThreadPool = Executors.newScheduledThreadPool(1, new CustomizableThreadFactory("cleanup-"));
|
scheduledThreadPool = Executors.newScheduledThreadPool(1, new CustomizableThreadFactory("cleanup-"));
|
||||||
|
|
||||||
final Path outputPath = Paths.get(outputDir);
|
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);
|
TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.http.CacheControl;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -69,9 +68,6 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
|||||||
@Value("${" + PRODUCTION_MODE + ":true}")
|
@Value("${" + PRODUCTION_MODE + ":true}")
|
||||||
private boolean modeProduction;
|
private boolean modeProduction;
|
||||||
|
|
||||||
@Value("${" + CACHE_IMAGES_DURATION_SECONDS + ":" + CACHE_IMAGES_DURATION_SECONDS_DEFAULT + "}")
|
|
||||||
private int cacheDurationInSeconds;
|
|
||||||
|
|
||||||
public PdbController(final PerformanceDb db, final Plotter plotter) {
|
public PdbController(final PerformanceDb db, final Plotter plotter) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.plotter = plotter;
|
this.plotter = plotter;
|
||||||
@@ -134,9 +130,7 @@ public class PdbController implements HardcodedValues, PropertyKeys {
|
|||||||
final PlotResponseStats stats = PlotResponseStats.fromDataSeries(result.getDataSeries());
|
final PlotResponseStats stats = PlotResponseStats.fromDataSeries(result.getDataSeries());
|
||||||
final PlotResponse plotResponse = new PlotResponse(stats, imageUrl, thumbnailUrl);
|
final PlotResponse plotResponse = new PlotResponse(stats, imageUrl, thumbnailUrl);
|
||||||
|
|
||||||
final CacheControl cacheControl = CacheControl.maxAge(cacheDurationInSeconds, TimeUnit.SECONDS);
|
return ResponseEntity.ok().body(plotResponse);
|
||||||
|
|
||||||
return ResponseEntity.ok().cacheControl(cacheControl).body(plotResponse);
|
|
||||||
} catch (final NoDataPointsException e) {
|
} catch (final NoDataPointsException e) {
|
||||||
throw new NotFoundException(e);
|
throw new NotFoundException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -12,16 +12,6 @@ public interface PropertyKeys {
|
|||||||
*/
|
*/
|
||||||
String TMP_DIR = "path.tmp";
|
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
|
* Indicates whether or not this instance is running in production. This
|
||||||
* property is used to switch Vue.js into production or development mode.
|
* property is used to switch Vue.js into production or development mode.
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package org.lucares.pdbui;
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
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.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
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 {
|
public class WebConfiguration implements WebMvcConfigurer, HardcodedValues, PropertyKeys {
|
||||||
|
|
||||||
private final String outputDir;
|
private final String outputDir;
|
||||||
private final int cacheDurationInSeconds;
|
|
||||||
|
|
||||||
public WebConfiguration(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir,
|
public WebConfiguration(@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir) {
|
||||||
@Value("${" + CACHE_IMAGES_DURATION_SECONDS + ":" + CACHE_IMAGES_DURATION_SECONDS_DEFAULT
|
|
||||||
+ "}") final int cacheDurationInSeconds) {
|
|
||||||
this.outputDir = outputDir;
|
this.outputDir = outputDir;
|
||||||
this.cacheDurationInSeconds = cacheDurationInSeconds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -28,7 +22,6 @@ public class WebConfiguration implements WebMvcConfigurer, HardcodedValues, Prop
|
|||||||
final String pathPattern = "/" + WEB_IMAGE_OUTPUT_PATH + "/**";
|
final String pathPattern = "/" + WEB_IMAGE_OUTPUT_PATH + "/**";
|
||||||
final String resourceLocation = "file:" + Paths.get(outputDir).toAbsolutePath() + "/";
|
final String resourceLocation = "file:" + Paths.get(outputDir).toAbsolutePath() + "/";
|
||||||
|
|
||||||
final CacheControl cacheControl = CacheControl.maxAge(cacheDurationInSeconds, TimeUnit.SECONDS);
|
registry.addResourceHandler(pathPattern).addResourceLocations(resourceLocation);
|
||||||
registry.addResourceHandler(pathPattern).addResourceLocations(resourceLocation).setCacheControl(cacheControl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,4 @@ db.base=${base.dir}/db
|
|||||||
path.tmp=${base.dir}/tmp
|
path.tmp=${base.dir}/tmp
|
||||||
path.output=${base.dir}/out
|
path.output=${base.dir}/out
|
||||||
|
|
||||||
cache.images.duration.seconds=3600
|
|
||||||
|
|
||||||
logging.config=classpath:log4j2.xml
|
logging.config=classpath:log4j2.xml
|
||||||
|
|||||||
Reference in New Issue
Block a user