[Notice] Announcing the End of Demo Server [Read me]
code-browser: Cache code browser page with ehcache
@a4dd951e33d2b49854404db92e95aeec9505ddf9
--- app/controllers/CodeApp.java
+++ app/controllers/CodeApp.java
... | ... | @@ -7,7 +7,6 @@ |
7 | 7 |
package controllers; |
8 | 8 |
|
9 | 9 |
import actions.CodeAccessCheckAction; |
10 |
-import actions.DefaultProjectCheckAction; |
|
11 | 10 |
import com.fasterxml.jackson.databind.node.ObjectNode; |
12 | 11 |
import controllers.annotation.AnonymousCheck; |
13 | 12 |
import controllers.annotation.IsAllowed; |
... | ... | @@ -18,6 +17,7 @@ |
18 | 17 |
import org.apache.tika.mime.MediaType; |
19 | 18 |
import org.eclipse.jgit.api.errors.GitAPIException; |
20 | 19 |
import org.tmatesoft.svn.core.SVNException; |
20 |
+import play.cache.Cache; |
|
21 | 21 |
import play.db.ebean.Transactional; |
22 | 22 |
import play.mvc.Controller; |
23 | 23 |
import play.mvc.Http; |
... | ... | @@ -36,6 +36,7 @@ |
36 | 36 |
import java.io.IOException; |
37 | 37 |
import java.net.URLEncoder; |
38 | 38 |
import java.util.Arrays; |
39 |
+import java.util.Date; |
|
39 | 40 |
import java.util.List; |
40 | 41 |
|
41 | 42 |
import static utils.HttpUtil.encodeUrlString; |
... | ... | @@ -81,9 +82,9 @@ |
81 | 82 |
} |
82 | 83 |
|
83 | 84 |
@With(CodeAccessCheckAction.class) |
84 |
- public static Result codeBrowserWithBranch(String userName, String projectName, String branch, String path) |
|
85 |
+ public static Result codeBrowserWithBranch(String owner, String projectName, String branch, String path) |
|
85 | 86 |
throws UnsupportedOperationException, IOException, SVNException, GitAPIException, ServletException { |
86 |
- Project project = Project.findByOwnerAndProjectName(userName, projectName); |
|
87 |
+ Project project = Project.findByOwnerAndProjectName(owner, projectName); |
|
87 | 88 |
|
88 | 89 |
if (!RepositoryService.VCS_GIT.equals(project.vcs) && !RepositoryService.VCS_SUBVERSION.equals(project.vcs)) { |
89 | 90 |
return status(Http.Status.NOT_IMPLEMENTED, project.vcs + " is not supported!"); |
... | ... | @@ -94,9 +95,13 @@ |
94 | 95 |
|
95 | 96 |
PlayRepository repository = RepositoryService.getRepository(project); |
96 | 97 |
List<String> branches = repository.getRefNames(); |
97 |
- List<ObjectNode> recursiveData = RepositoryService.getMetaDataFromAncestorDirectories( |
|
98 |
- repository, branch, path); |
|
99 |
- |
|
98 |
+ String cacheKey = owner + ":" + projectName + ":" + branch + ":" + path + ":" + project.lastUpdateDate().getTime(); |
|
99 |
+ List<ObjectNode> recursiveData = (List<ObjectNode>) Cache.get(cacheKey); |
|
100 |
+ if( recursiveData == null){ |
|
101 |
+ recursiveData = RepositoryService.getMetaDataFromAncestorDirectories( |
|
102 |
+ repository, branch, path); |
|
103 |
+ Cache.set(cacheKey, recursiveData); |
|
104 |
+ } |
|
100 | 105 |
if (recursiveData == null) { |
101 | 106 |
return notFound(ErrorViews.NotFound.render()); |
102 | 107 |
} |
+++ conf/ehcache.xml
... | ... | @@ -0,0 +1,18 @@ |
1 | +<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false"> | |
2 | + | |
3 | + <!-- This is a default configuration for 50Mb of cached data using the JVM's heap, but it must be adjusted | |
4 | + according to specific requirement and heap sizes --> | |
5 | + | |
6 | + <defaultCache | |
7 | + maxElementsInMemory="1000" | |
8 | + eternal="false" | |
9 | + timeToIdleSeconds="0" | |
10 | + timeToLiveSeconds="0" | |
11 | + overflowToDisk="false" | |
12 | + maxElementsOnDisk="999" | |
13 | + diskPersistent="false" | |
14 | + diskExpiryThreadIntervalSeconds="120" | |
15 | + memoryStoreEvictionPolicy="LRU" | |
16 | + /> | |
17 | + | |
18 | +</ehcache> |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?