Cache documents that are loaded from HEAD only for a short period

HEAD is modifable, hence documents loaded from it should be cached
only for a short period.

Change-Id: I45691ad94d56c898953fea7fb8aa579f17b8d9f2
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
index 0c2b368..3863da9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
@@ -172,7 +172,13 @@
           res.setHeader(HttpHeaders.ETAG,
               computeETag(key.project, revId, key.file, revIdB, key.diffMode));
         }
-        CacheHeaders.setCacheablePrivate(res, 7, TimeUnit.DAYS, false);
+        if (key.diffMode == DiffMode.NO_DIFF && rev == null) {
+          // file was loaded from HEAD, since HEAD is modifiable the document
+          // should only be cached for a short period
+          CacheHeaders.setCacheablePrivate(res, 15, TimeUnit.MINUTES, false);
+        } else {
+          CacheHeaders.setCacheablePrivate(res, 7, TimeUnit.DAYS, false);
+        }
         rsc.send(req, res);
         return;
       } finally {