Move GetChange#cache to a better-named Response static factory
The old method wasn't telling the client to not cache per se, but instead to use the cached version after revalidation. "Cache" was sufficiently generic to be confusing. Move this to a factory method in Response, and give it the slightly more descriptive name withMustRevalidate. Change-Id: Ic0bf486637f4542de3a2e6088eff1fee2d26c0d7
This commit is contained in:
parent
44cea2e2a5
commit
6928a0f1c5
@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.extensions.restapi;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** Special return value to mean specific HTTP status codes in a REST API. */
|
||||
public abstract class Response<T> {
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
@ -24,6 +26,11 @@ public abstract class Response<T> {
|
||||
return new Impl<>(200, value);
|
||||
}
|
||||
|
||||
public static <T> Response<T> withMustRevalidate(T value) {
|
||||
return ok(value).caching(
|
||||
CacheControl.PRIVATE(0, TimeUnit.SECONDS).setMustRevalidate());
|
||||
}
|
||||
|
||||
/** HTTP 201 Created: typically used when a new resource is made. */
|
||||
public static <T> Response<T> created(T value) {
|
||||
return new Impl<>(201, value);
|
||||
|
@ -37,7 +37,7 @@ public class Check implements RestReadView<ChangeResource>,
|
||||
|
||||
@Override
|
||||
public Response<ChangeInfo> apply(ChangeResource rsrc) throws OrmException {
|
||||
return GetChange.cache(json.format(rsrc));
|
||||
return Response.withMustRevalidate(json.format(rsrc));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,6 +49,6 @@ public class Check implements RestReadView<ChangeResource>,
|
||||
&& !ctl.getCurrentUser().getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("Not owner");
|
||||
}
|
||||
return GetChange.cache(json.fix(input).format(rsrc));
|
||||
return Response.withMustRevalidate(json.fix(input).format(rsrc));
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ListChangesOption;
|
||||
import com.google.gerrit.extensions.restapi.CacheControl;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@ -24,8 +23,6 @@ import com.google.inject.Inject;
|
||||
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GetChange implements RestReadView<ChangeResource> {
|
||||
private final ChangeJson json;
|
||||
|
||||
@ -46,15 +43,10 @@ public class GetChange implements RestReadView<ChangeResource> {
|
||||
|
||||
@Override
|
||||
public Response<ChangeInfo> apply(ChangeResource rsrc) throws OrmException {
|
||||
return cache(json.format(rsrc));
|
||||
return Response.withMustRevalidate(json.format(rsrc));
|
||||
}
|
||||
|
||||
Response<ChangeInfo> apply(RevisionResource rsrc) throws OrmException {
|
||||
return cache(json.format(rsrc));
|
||||
}
|
||||
|
||||
static Response<ChangeInfo> cache(ChangeInfo res) {
|
||||
return Response.ok(res)
|
||||
.caching(CacheControl.PRIVATE(0, TimeUnit.SECONDS).setMustRevalidate());
|
||||
return Response.withMustRevalidate(json.format(rsrc));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user