Skip to content

Commit

Permalink
code-browser: Cache code browser page with ehcache
Browse files Browse the repository at this point in the history
  • Loading branch information
doortts committed Mar 13, 2017
1 parent 36a2f6f commit a4dd951
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/controllers/CodeApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package controllers;

import actions.CodeAccessCheckAction;
import actions.DefaultProjectCheckAction;
import com.fasterxml.jackson.databind.node.ObjectNode;
import controllers.annotation.AnonymousCheck;
import controllers.annotation.IsAllowed;
Expand All @@ -18,6 +17,7 @@
import org.apache.tika.mime.MediaType;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.tmatesoft.svn.core.SVNException;
import play.cache.Cache;
import play.db.ebean.Transactional;
import play.mvc.Controller;
import play.mvc.Http;
Expand All @@ -36,6 +36,7 @@
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static utils.HttpUtil.encodeUrlString;
Expand Down Expand Up @@ -81,9 +82,9 @@ public static Result codeBrowser(String userName, String projectName)
}

@With(CodeAccessCheckAction.class)
public static Result codeBrowserWithBranch(String userName, String projectName, String branch, String path)
public static Result codeBrowserWithBranch(String owner, String projectName, String branch, String path)
throws UnsupportedOperationException, IOException, SVNException, GitAPIException, ServletException {
Project project = Project.findByOwnerAndProjectName(userName, projectName);
Project project = Project.findByOwnerAndProjectName(owner, projectName);

if (!RepositoryService.VCS_GIT.equals(project.vcs) && !RepositoryService.VCS_SUBVERSION.equals(project.vcs)) {
return status(Http.Status.NOT_IMPLEMENTED, project.vcs + " is not supported!");
Expand All @@ -94,9 +95,13 @@ public static Result codeBrowserWithBranch(String userName, String projectName,

PlayRepository repository = RepositoryService.getRepository(project);
List<String> branches = repository.getRefNames();
List<ObjectNode> recursiveData = RepositoryService.getMetaDataFromAncestorDirectories(
repository, branch, path);

String cacheKey = owner + ":" + projectName + ":" + branch + ":" + path + ":" + project.lastUpdateDate().getTime();
List<ObjectNode> recursiveData = (List<ObjectNode>) Cache.get(cacheKey);
if( recursiveData == null){
recursiveData = RepositoryService.getMetaDataFromAncestorDirectories(
repository, branch, path);
Cache.set(cacheKey, recursiveData);
}
if (recursiveData == null) {
return notFound(ErrorViews.NotFound.render());
}
Expand Down
18 changes: 18 additions & 0 deletions conf/ehcache.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false">

<!-- This is a default configuration for 50Mb of cached data using the JVM's heap, but it must be adjusted
according to specific requirement and heap sizes -->

<defaultCache
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
maxElementsOnDisk="999"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>

</ehcache>

0 comments on commit a4dd951

Please sign in to comment.