Disable caching for revision URLs using "current"

The current revision is resolved dynamically and may change. Do
not allow browser level caching on these URLs as the contents can
(and usually does) change in the future.

Clients that want caching must request the revision-id using a stable
identifier, ideally the commit SHA-1, or at least the unique patch
set number. This allows contents to cache as data behind the URL
will not change.

Change-Id: I00c5c607a78297dadaf5d5338f025aaf4832af63
This commit is contained in:
Shawn Pearce
2013-07-12 10:21:41 -07:00
parent 18f26bd6b7
commit c2cb3cda1d
6 changed files with 33 additions and 7 deletions

View File

@@ -35,7 +35,10 @@ public class GetCommit implements RestReadView<RevisionResource> {
@Override
public Response<CommitInfo> apply(RevisionResource resource)
throws OrmException, PatchSetInfoNotAvailableException {
return Response.ok(json.toCommit(resource.getPatchSet()))
.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
Response<CommitInfo> r = Response.ok(json.toCommit(resource.getPatchSet()));
if (resource.isCacheable()) {
r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
}
return r;
}
}