From 9359865cf1571d69a464387abb2b0b2c4982580d Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 24 Jul 2013 11:50:50 -0400
Subject: [PATCH] Documentation
---
src/main/java/com/gitblit/utils/CommitCache.java | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/gitblit/utils/CommitCache.java b/src/main/java/com/gitblit/utils/CommitCache.java
index e188ff9..e84506e 100644
--- a/src/main/java/com/gitblit/utils/CommitCache.java
+++ b/src/main/java/com/gitblit/utils/CommitCache.java
@@ -67,7 +67,7 @@
*
* @return
*/
- protected Date getCacheCutoffDate() {
+ public Date getCutoffDate() {
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.HOUR_OF_DAY, 0);
@@ -110,6 +110,23 @@
}
/**
+ * Clears the commit cache for a specific branch of a specific repository.
+ *
+ * @param repositoryName
+ * @param branch
+ */
+ public void clear(String repositoryName, String branch) {
+ String repoKey = repositoryName.toLowerCase();
+ ObjectCache<List<RepositoryCommit>> repoCache = cache.get(repoKey);
+ if (repoCache != null) {
+ List<RepositoryCommit> commits = repoCache.remove(branch.toLowerCase());
+ if (!ArrayUtils.isEmpty(commits)) {
+ logger.info(MessageFormat.format("{0}:{1} commit cache cleared", repositoryName, branch));
+ }
+ }
+ }
+
+ /**
* Get all commits for the specified repository:branch that are in the cache.
*
* @param repositoryName
@@ -118,7 +135,7 @@
* @return a list of commits
*/
public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch) {
- return getCommits(repositoryName, repository, branch, getCacheCutoffDate());
+ return getCommits(repositoryName, repository, branch, getCutoffDate());
}
/**
@@ -134,7 +151,7 @@
*/
public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch, Date sinceDate) {
long start = System.nanoTime();
- Date cacheCutoffDate = getCacheCutoffDate();
+ Date cacheCutoffDate = getCutoffDate();
List<RepositoryCommit> list;
if (cacheDays > 0 && (sinceDate.getTime() >= cacheCutoffDate.getTime())) {
// request fits within the cache window
--
Gitblit v1.9.1