ChangeScreen2: Allow browser caching of /detail

When sending /detail responses to the browser allow the data to
be cached locally at the browser. Use HTTP standard Last-Modified
and If-Modified-Since HTTP response and request headers to manage
cache invalidation when the change has been updated.

This permits the server to skip out early and avoid formatting JSON
for the change if nothing has happened to the change since the last
view since by this user. This can save hundreds of milliseconds in
response time when revisting a recently viewed change.

Change-Id: Ifab60d58a454adccfb75c542fd64df147c463c1f
This commit is contained in:
Shawn Pearce
2013-07-18 12:42:27 -07:00
parent dd30152179
commit 5b568d326d
6 changed files with 107 additions and 16 deletions

View File

@@ -35,6 +35,7 @@ public class CacheControl {
private final Type type;
private final long age;
private final TimeUnit unit;
private boolean mustRevalidate;
private CacheControl(Type type, long age, TimeUnit unit) {
this.type = type;
@@ -53,4 +54,13 @@ public class CacheControl {
public TimeUnit getUnit() {
return unit;
}
public boolean isMustRevalidate() {
return mustRevalidate;
}
public CacheControl setMustRevalidate() {
mustRevalidate = true;
return this;
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.extensions.restapi;
import java.sql.Timestamp;
/**
* Generic resource handle defining arguments to views.
* <p>
@@ -21,4 +23,9 @@ package com.google.gerrit.extensions.restapi;
* {@link RestView} such as {@link RestReadView} or {@link RestModifyView}.
*/
public interface RestResource {
/** A resource with a last modification date. */
public interface HasLastModified {
public Timestamp getLastModified();
}
}