| | |
| | | * |
| | | * @return |
| | | */ |
| | | protected Date getCacheCutoffDate() { |
| | | public Date getCutoffDate() { |
| | | final Calendar cal = Calendar.getInstance(); |
| | | cal.setTimeInMillis(System.currentTimeMillis()); |
| | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | * @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()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | 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 |