summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2015-11-24 16:35:44 -0500
committerDave Borowitz <dborowitz@google.com>2015-11-24 16:35:44 -0500
commitc05d8a705c535b225d2fb21047950d583b82174e (patch)
tree05770800a8193bc2fbae3743861d7748038bec59
parentc7163d5efb68ef075db803f73ba78fb80a9d478c (diff)
ResourceServlet: Fix refreshing stale resources
In 74317d4a, the r.isStale call got incorrectly hidden behind an r == null check, resulting in the resource not getting refreshed if it was previously cached. Move the r.isStale call up one level so resources are refreshed correctly. Change-Id: I995e9794b3549a324e2d427af3c0befd73768294
-rw-r--r--gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ResourceServlet.java33
1 files changed, 15 insertions, 18 deletions
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ResourceServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ResourceServlet.java
index a804e2a5d7..507bc59812 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ResourceServlet.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ResourceServlet.java
@@ -130,28 +130,25 @@ public abstract class ResourceServlet extends HttpServlet {
}
Resource r = cache.getIfPresent(p);
- if (r == null && maybeStream(p, req, rsp)) {
- return;
- }
-
- if (r == null) {
- Callable<Resource> loader = newLoader(p);
- try {
- r = cache.get(p, loader);
- if (refresh && r.isStale(p, this)) {
- cache.invalidate(p);
- r = cache.get(p, loader);
+ try {
+ if (r == null) {
+ if (maybeStream(p, req, rsp)) {
+ return; // Bypass cache for large resource.
}
- } catch (ExecutionException | IOException e) {
- log.warn("Cannot load static resource " + req.getPathInfo(), e);
- CacheHeaders.setNotCacheable(rsp);
- rsp.setStatus(SC_INTERNAL_SERVER_ERROR);
- return;
+ r = cache.get(p, newLoader(p));
+ }
+ if (refresh && r.isStale(p, this)) {
+ cache.invalidate(p);
+ r = cache.get(p, newLoader(p));
}
+ } catch (ExecutionException e) {
+ log.warn("Cannot load static resource " + req.getPathInfo(), e);
+ CacheHeaders.setNotCacheable(rsp);
+ rsp.setStatus(SC_INTERNAL_SERVER_ERROR);
+ return;
}
-
if (r == Resource.NOT_FOUND) {
- notFound(rsp);
+ notFound(rsp); // Cached not found response.
return;
}