diff options
Diffstat (limited to 'src/main/java/com/gitblit/wicket/pages')
25 files changed, 182 insertions, 6 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/ActivityPage.java b/src/main/java/com/gitblit/wicket/pages/ActivityPage.java index 694fa603..413403b4 100644 --- a/src/main/java/com/gitblit/wicket/pages/ActivityPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ActivityPage.java @@ -35,7 +35,9 @@ import com.gitblit.models.Metric; import com.gitblit.models.RepositoryModel;
import com.gitblit.utils.ActivityUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.PageRegistration;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.PageRegistration.DropDownMenuItem;
import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;
import com.gitblit.wicket.WicketUtils;
@@ -52,6 +54,8 @@ import com.gitblit.wicket.panels.ActivityPanel; * @author James Moger
*
*/
+
+@CacheControl(LastModified.ACTIVITY)
public class ActivityPage extends RootPage {
public ActivityPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index 71713cd9..c9e11b08 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -40,7 +40,10 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.protocol.http.RequestUtils;
+import org.apache.wicket.protocol.http.WebResponse;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
+import org.apache.wicket.util.time.Duration;
+import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,6 +59,7 @@ import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebApp;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
@@ -121,7 +125,68 @@ public abstract class BasePage extends SessionPage { Application.get().getMarkupSettings().setStripWicketTags(false);
}
super.onAfterRender();
- }
+ }
+
+ @Override
+ protected void setHeaders(WebResponse response) {
+ int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0);
+ if (expires > 0) {
+ // pages are personalized for the authenticated user so they must be
+ // marked private to prohibit proxy servers from caching them
+ response.setHeader("Cache-Control", "private, must-revalidate");
+ setLastModified();
+ } else {
+ // use default Wicket caching behavior
+ super.setHeaders(response);
+ }
+ }
+
+ /**
+ * Sets the last-modified header date, if appropriate, for this page. The
+ * date used is determined by the CacheControl annotation.
+ *
+ */
+ protected void setLastModified() {
+ if (getClass().isAnnotationPresent(CacheControl.class)) {
+ CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
+ switch (cacheControl.value()) {
+ case ACTIVITY:
+ setLastModified(GitBlit.getLastActivityDate());
+ break;
+ case BOOT:
+ setLastModified(GitBlit.getBootDate());
+ break;
+ case NONE:
+ break;
+ default:
+ logger.warn(getClass().getSimpleName() + ": unhandled LastModified type " + cacheControl.value());
+ break;
+ }
+ }
+ }
+
+ /**
+ * Sets the last-modified header field and the expires field.
+ *
+ * @param when
+ */
+ protected final void setLastModified(Date when) {
+ if (when == null) {
+ return;
+ }
+
+ if (when.before(GitBlit.getBootDate())) {
+ // last-modified can not be before the Gitblit boot date
+ // this helps ensure that pages are properly refreshed after a
+ // server config change
+ when = GitBlit.getBootDate();
+ }
+
+ int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0);
+ WebResponse response = (WebResponse) getResponse();
+ response.setLastModifiedTime(Time.valueOf(when));
+ response.setDateHeader("Expires", System.currentTimeMillis() + Duration.minutes(expires).getMilliseconds());
+ }
protected void setupPage(String repositoryName, String pageName) {
String siteName = GitBlit.getString(Keys.web.siteName, Constants.NAME);
diff --git a/src/main/java/com/gitblit/wicket/pages/BlamePage.java b/src/main/java/com/gitblit/wicket/pages/BlamePage.java index 51489150..53bd233d 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlamePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlamePage.java @@ -37,11 +37,14 @@ import com.gitblit.models.PathModel; import com.gitblit.utils.DiffUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
+@CacheControl(LastModified.BOOT)
public class BlamePage extends RepositoryPage {
public BlamePage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java index 03edaa31..c297bcaf 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java @@ -27,10 +27,13 @@ import com.gitblit.utils.DiffUtils; import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
+@CacheControl(LastModified.BOOT)
public class BlobDiffPage extends RepositoryPage {
public BlobDiffPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/BlobPage.java b/src/main/java/com/gitblit/wicket/pages/BlobPage.java index f6e99988..b104df2d 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobPage.java @@ -32,11 +32,14 @@ import com.gitblit.GitBlit; import com.gitblit.Keys;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.ExternalImage;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
+@CacheControl(LastModified.BOOT)
public class BlobPage extends RepositoryPage {
protected String fileExtension;
diff --git a/src/main/java/com/gitblit/wicket/pages/BranchesPage.java b/src/main/java/com/gitblit/wicket/pages/BranchesPage.java index 8684fb3d..fe7483e4 100644 --- a/src/main/java/com/gitblit/wicket/pages/BranchesPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BranchesPage.java @@ -17,8 +17,11 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.BranchesPanel;
+@CacheControl(LastModified.REPOSITORY)
public class BranchesPage extends RepositoryPage {
public BranchesPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java index 6954808d..6f1b4598 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java @@ -16,7 +16,6 @@ package com.gitblit.wicket.pages; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.wicket.PageParameters; @@ -30,22 +29,21 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; -import com.gitblit.Constants; import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.PathModel.PathChangeModel; -import com.gitblit.models.GitNote; import com.gitblit.models.SubmoduleModel; import com.gitblit.utils.DiffUtils; import com.gitblit.utils.DiffUtils.DiffOutputType; import com.gitblit.utils.JGitUtils; +import com.gitblit.wicket.CacheControl; +import com.gitblit.wicket.CacheControl.LastModified; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.CommitHeaderPanel; import com.gitblit.wicket.panels.CommitLegendPanel; -import com.gitblit.wicket.panels.GravatarImage; import com.gitblit.wicket.panels.LinkPanel; -import com.gitblit.wicket.panels.RefsPanel; +@CacheControl(LastModified.BOOT) public class CommitDiffPage extends RepositoryPage { public CommitDiffPage(PageParameters params) { diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.java b/src/main/java/com/gitblit/wicket/pages/CommitPage.java index b98dba5b..1d11d443 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.java @@ -37,6 +37,8 @@ import com.gitblit.models.GitNote; import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.utils.JGitUtils;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CommitLegendPanel;
@@ -45,6 +47,7 @@ import com.gitblit.wicket.panels.GravatarImage; import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
+@CacheControl(LastModified.BOOT)
public class CommitPage extends RepositoryPage {
public CommitPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/DocsPage.java b/src/main/java/com/gitblit/wicket/pages/DocsPage.java index 9ddc98d3..9330316e 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocsPage.java @@ -30,9 +30,12 @@ import com.gitblit.Keys; import com.gitblit.models.PathModel;
import com.gitblit.utils.ByteFormat;
import com.gitblit.utils.JGitUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.LinkPanel;
+@CacheControl(LastModified.REPOSITORY)
public class DocsPage extends RepositoryPage {
public DocsPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/GitSearchPage.java b/src/main/java/com/gitblit/wicket/pages/GitSearchPage.java index 154bdcc7..446531ab 100644 --- a/src/main/java/com/gitblit/wicket/pages/GitSearchPage.java +++ b/src/main/java/com/gitblit/wicket/pages/GitSearchPage.java @@ -19,9 +19,12 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import com.gitblit.Constants;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.SearchPanel;
+@CacheControl(LastModified.REPOSITORY)
public class GitSearchPage extends RepositoryPage {
public GitSearchPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/HistoryPage.java b/src/main/java/com/gitblit/wicket/pages/HistoryPage.java index 314bdef7..33bc54c1 100644 --- a/src/main/java/com/gitblit/wicket/pages/HistoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/HistoryPage.java @@ -18,9 +18,12 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.HistoryPanel;
+@CacheControl(LastModified.REPOSITORY)
public class HistoryPage extends RepositoryPage {
public HistoryPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/LogPage.java b/src/main/java/com/gitblit/wicket/pages/LogPage.java index ee8ddfef..1f4a9bf9 100644 --- a/src/main/java/com/gitblit/wicket/pages/LogPage.java +++ b/src/main/java/com/gitblit/wicket/pages/LogPage.java @@ -19,9 +19,12 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.LogPanel;
+@CacheControl(LastModified.REPOSITORY)
public class LogPage extends RepositoryPage {
public LogPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java b/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java index 7f82b648..df078c72 100644 --- a/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java +++ b/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java @@ -29,8 +29,11 @@ import com.gitblit.GitBlit; import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
+@CacheControl(LastModified.BOOT)
public class MarkdownPage extends RepositoryPage {
public MarkdownPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/MetricsPage.java b/src/main/java/com/gitblit/wicket/pages/MetricsPage.java index 3195020d..3aa1fccd 100644 --- a/src/main/java/com/gitblit/wicket/pages/MetricsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/MetricsPage.java @@ -40,9 +40,12 @@ import org.wicketstuff.googlecharts.ShapeMarker; import com.gitblit.models.Metric;
import com.gitblit.utils.MetricUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.charting.SecureChart;
+@CacheControl(LastModified.REPOSITORY)
public class MetricsPage extends RepositoryPage {
public MetricsPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java b/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java index d951da31..32c128da 100644 --- a/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java +++ b/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java @@ -43,11 +43,14 @@ import com.gitblit.models.UserModel; import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.FilterableProjectList;
import com.gitblit.wicket.panels.FilterableRepositoryList;
+@CacheControl(LastModified.ACTIVITY)
public class MyDashboardPage extends DashboardPage {
public MyDashboardPage() {
diff --git a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java index ff6326d4..e1de9f39 100644 --- a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java +++ b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java @@ -34,8 +34,10 @@ import com.gitblit.models.Metric; import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.JGitUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.charting.GoogleChart;
import com.gitblit.wicket.charting.GoogleCharts;
import com.gitblit.wicket.charting.GoogleLineChart;
@@ -45,6 +47,7 @@ import com.gitblit.wicket.panels.ReflogPanel; import com.gitblit.wicket.panels.RepositoryUrlPanel;
import com.gitblit.wicket.panels.TagsPanel;
+@CacheControl(LastModified.REPOSITORY)
public class OverviewPage extends RepositoryPage {
public OverviewPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/PatchPage.java b/src/main/java/com/gitblit/wicket/pages/PatchPage.java index 878cfb45..be959d01 100644 --- a/src/main/java/com/gitblit/wicket/pages/PatchPage.java +++ b/src/main/java/com/gitblit/wicket/pages/PatchPage.java @@ -25,9 +25,12 @@ import com.gitblit.GitBlit; import com.gitblit.utils.DiffUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
+@CacheControl(LastModified.BOOT)
public class PatchPage extends WebPage {
public PatchPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/ProjectPage.java b/src/main/java/com/gitblit/wicket/pages/ProjectPage.java index 97a31f98..c9388913 100644 --- a/src/main/java/com/gitblit/wicket/pages/ProjectPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ProjectPage.java @@ -33,6 +33,8 @@ import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.GitBlitWebApp;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.GitblitRedirectException;
@@ -42,6 +44,7 @@ import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration; import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.FilterableRepositoryList;
+@CacheControl(LastModified.PROJECT)
public class ProjectPage extends DashboardPage {
List<ProjectModel> projectModels = new ArrayList<ProjectModel>();
@@ -60,6 +63,26 @@ public class ProjectPage extends DashboardPage { return RepositoriesPage.class;
}
+ @Override
+ protected void setLastModified() {
+ if (getClass().isAnnotationPresent(CacheControl.class)) {
+ CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
+ switch (cacheControl.value()) {
+ case PROJECT:
+ String projectName = WicketUtils.getProjectName(getPageParameters());
+ if (!StringUtils.isEmpty(projectName)) {
+ ProjectModel project = getProjectModel(projectName);
+ if (project != null) {
+ setLastModified(project.lastChange);
+ }
+ }
+ break;
+ default:
+ super.setLastModified();
+ }
+ }
+ }
+
private void setup(PageParameters params) {
setupPage("", "");
// check to see if we should display a login message
diff --git a/src/main/java/com/gitblit/wicket/pages/ReflogPage.java b/src/main/java/com/gitblit/wicket/pages/ReflogPage.java index 884f6167..c97b2cc1 100644 --- a/src/main/java/com/gitblit/wicket/pages/ReflogPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ReflogPage.java @@ -18,9 +18,12 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.ReflogPanel;
+@CacheControl(LastModified.REPOSITORY)
public class ReflogPage extends RepositoryPage {
public ReflogPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java index 7d4d68c7..a4a1ab58 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java @@ -33,13 +33,16 @@ import com.gitblit.Keys; import com.gitblit.models.RepositoryModel;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.PageRegistration;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.PageRegistration.DropDownMenuItem;
import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.RepositoriesPanel;
+@CacheControl(LastModified.ACTIVITY)
public class RepositoriesPage extends RootPage {
public RepositoriesPage() {
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java index 372b68d0..f5b8c96e 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java @@ -19,6 +19,7 @@ import java.io.Serializable; import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -63,6 +64,7 @@ import com.gitblit.utils.JGitUtils; import com.gitblit.utils.RefLogUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TicgitUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.PageRegistration;
import com.gitblit.wicket.PageRegistration.OtherPageLink;
@@ -572,6 +574,30 @@ public abstract class RepositoryPage extends RootPage { setupPage(repositoryName, "/ " + getPageName());
super.onBeforeRender();
}
+
+ @Override
+ protected void setLastModified() {
+ if (getClass().isAnnotationPresent(CacheControl.class)) {
+ CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
+ switch (cacheControl.value()) {
+ case REPOSITORY:
+ RepositoryModel repository = getRepositoryModel();
+ if (repository != null) {
+ setLastModified(repository.lastChange);
+ }
+ break;
+ case COMMIT:
+ RevCommit commit = getCommit();
+ if (commit != null) {
+ Date commitDate = JGitUtils.getCommitDate(commit);
+ setLastModified(commitDate);
+ }
+ break;
+ default:
+ super.setLastModified();
+ }
+ }
+ }
protected PageParameters newRepositoryParameter() {
return WicketUtils.newRepositoryParameter(repositoryName);
diff --git a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java index c231b2ba..17c41eb2 100644 --- a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java @@ -50,8 +50,10 @@ import com.gitblit.models.UserModel; import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.charting.SecureChart;
import com.gitblit.wicket.panels.BranchesPanel;
import com.gitblit.wicket.panels.LinkPanel;
@@ -59,6 +61,7 @@ import com.gitblit.wicket.panels.LogPanel; import com.gitblit.wicket.panels.RepositoryUrlPanel;
import com.gitblit.wicket.panels.TagsPanel;
+@CacheControl(LastModified.REPOSITORY)
public class SummaryPage extends RepositoryPage {
public SummaryPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/TagPage.java b/src/main/java/com/gitblit/wicket/pages/TagPage.java index 6deef783..13c10111 100644 --- a/src/main/java/com/gitblit/wicket/pages/TagPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TagPage.java @@ -28,11 +28,14 @@ import org.eclipse.jgit.lib.Repository; import com.gitblit.models.RefModel;
import com.gitblit.utils.JGitUtils;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.GravatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
+@CacheControl(LastModified.BOOT)
public class TagPage extends RepositoryPage {
public TagPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/TagsPage.java b/src/main/java/com/gitblit/wicket/pages/TagsPage.java index b052531e..2abb410a 100644 --- a/src/main/java/com/gitblit/wicket/pages/TagsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TagsPage.java @@ -17,8 +17,11 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.panels.TagsPanel;
+@CacheControl(LastModified.REPOSITORY)
public class TagsPage extends RepositoryPage {
public TagsPage(PageParameters params) {
diff --git a/src/main/java/com/gitblit/wicket/pages/TreePage.java b/src/main/java/com/gitblit/wicket/pages/TreePage.java index bc27f0c2..25bcd67a 100644 --- a/src/main/java/com/gitblit/wicket/pages/TreePage.java +++ b/src/main/java/com/gitblit/wicket/pages/TreePage.java @@ -33,12 +33,15 @@ import com.gitblit.models.PathModel; import com.gitblit.models.SubmoduleModel;
import com.gitblit.utils.ByteFormat;
import com.gitblit.utils.JGitUtils;
+import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CompressedDownloadsPanel;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
+@CacheControl(LastModified.BOOT)
public class TreePage extends RepositoryPage {
public TreePage(PageParameters params) {
|