do not cache resource urls in development stage, to avoid stale data

This commit is contained in:
Sebastian Sdorra
2018-10-29 14:55:56 +01:00
parent 95a7450e38
commit 1b60095373
2 changed files with 42 additions and 17 deletions

View File

@@ -41,6 +41,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.SCMContext;
import sonia.scm.Stage;
import javax.servlet.ServletContext;
import java.net.MalformedURLException;
@@ -69,19 +71,21 @@ public class DefaultUberWebResourceLoader implements UberWebResourceLoader
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param servletContext
* @param plugins
*/
public DefaultUberWebResourceLoader(ServletContext servletContext,
Iterable<PluginWrapper> plugins)
{
public DefaultUberWebResourceLoader(ServletContext servletContext, Iterable<PluginWrapper> plugins) {
this(servletContext, plugins, SCMContext.getContext().getStage());
}
public DefaultUberWebResourceLoader(ServletContext servletContext, Iterable<PluginWrapper> plugins, Stage stage) {
this.servletContext = servletContext;
this.plugins = plugins;
this.cache = CacheBuilder.newBuilder().build();
this.cache = createCache(stage);
}
private final Cache<String, URL> createCache(Stage stage) {
if (stage == Stage.DEVELOPMENT) {
return null;
}
return CacheBuilder.newBuilder().build();
}
//~--- get methods ----------------------------------------------------------
@@ -97,7 +101,7 @@ public class DefaultUberWebResourceLoader implements UberWebResourceLoader
@Override
public URL getResource(String path)
{
URL resource = cache.getIfPresent(path);
URL resource = getFromCache(path);
if (resource == null)
{
@@ -105,7 +109,7 @@ public class DefaultUberWebResourceLoader implements UberWebResourceLoader
if (resource != null)
{
cache.put(path, resource);
addToCache(path, resource);
}
}
else
@@ -116,6 +120,19 @@ public class DefaultUberWebResourceLoader implements UberWebResourceLoader
return resource;
}
private URL getFromCache(String path) {
if (cache != null) {
return cache.getIfPresent(path);
}
return null;
}
private void addToCache(String path, URL url) {
if (cache != null) {
cache.put(path, url);
}
}
/**
* Method description
*