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
This commit is contained in:
@@ -130,28 +130,25 @@ public abstract class ResourceServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
Resource r = cache.getIfPresent(p);
|
||||
if (r == null && maybeStream(p, req, rsp)) {
|
||||
try {
|
||||
if (r == null) {
|
||||
if (maybeStream(p, req, rsp)) {
|
||||
return; // Bypass cache for large resource.
|
||||
}
|
||||
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 == 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);
|
||||
}
|
||||
} catch (ExecutionException | IOException 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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user