Use cache with size zero to avoid null checks

This commit is contained in:
Rene Pfeuffer
2018-11-01 10:35:51 +01:00
parent 7c50614b56
commit 4f30644e7d

View File

@@ -81,9 +81,9 @@ public class DefaultUberWebResourceLoader implements UberWebResourceLoader
this.cache = createCache(stage); this.cache = createCache(stage);
} }
private final Cache<String, URL> createCache(Stage stage) { private Cache<String, URL> createCache(Stage stage) {
if (stage == Stage.DEVELOPMENT) { if (stage == Stage.DEVELOPMENT) {
return null; return CacheBuilder.newBuilder().maximumSize(0).build(); // Disable caching
} }
return CacheBuilder.newBuilder().build(); return CacheBuilder.newBuilder().build();
} }
@@ -121,16 +121,11 @@ public class DefaultUberWebResourceLoader implements UberWebResourceLoader
} }
private URL getFromCache(String path) { private URL getFromCache(String path) {
if (cache != null) { return cache.getIfPresent(path);
return cache.getIfPresent(path);
}
return null;
} }
private void addToCache(String path, URL url) { private void addToCache(String path, URL url) {
if (cache != null) { cache.put(path, url);
cache.put(path, url);
}
} }
/** /**