]> source.dussan.org Git - archiva.git/commitdiff
add a bit of caching here at least for released version
authorOlivier Lamy <olamy@apache.org>
Thu, 27 Mar 2014 06:02:33 +0000 (06:02 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 27 Mar 2014 06:02:33 +0000 (06:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1582203 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml

index b16d7044076c791a6f89c42e0ae39ad9482b5387..348a2dd51f96d7dc25f7c463cae08e442d9efea6 100644 (file)
@@ -41,6 +41,7 @@ import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.archiva.model.ArchivaArtifact;
 import org.apache.archiva.model.ArchivaRepositoryMetadata;
 import org.apache.archiva.proxy.model.RepositoryProxyConnectors;
+import org.apache.archiva.redback.components.cache.Cache;
 import org.apache.archiva.repository.ManagedRepositoryContent;
 import org.apache.archiva.repository.RepositoryContentFactory;
 import org.apache.archiva.repository.RepositoryException;
@@ -103,6 +104,10 @@ public class DefaultBrowseService
     @Named( value = "repositoryProxyConnectors#default" )
     private RepositoryProxyConnectors connectors;
 
+    @Inject
+    @Named( value = "browse#versionMetadata" )
+    private Cache<String, ProjectVersionMetadata> versionMetadataCache;
+
     public BrowseResult getRootGroups( String repositoryId )
         throws ArchivaRestServiceException
     {
@@ -333,9 +338,35 @@ public class DefaultBrowseService
                     {
                         try
                         {
-                            versionMetadata =
-                                metadataResolver.resolveProjectVersion( repositorySession, repoId, groupId, artifactId,
-                                                                        version );
+                            ProjectVersionMetadata projectVersionMetadataResolved = null;
+                            boolean useCache = !StringUtils.endsWith( version, VersionUtil.SNAPSHOT );
+                            String cacheKey = null;
+                            boolean cacheToUpdate = false;
+                            // FIXME a bit maven centric!!!
+                            // not a snapshot so get it from cache
+                            if ( useCache )
+                            {
+                                cacheKey = repoId + groupId + artifactId + version;
+                                projectVersionMetadataResolved = versionMetadataCache.get( cacheKey );
+                            }
+                            if ( useCache && projectVersionMetadataResolved != null )
+                            {
+                                versionMetadata = projectVersionMetadataResolved;
+                            }
+                            else
+                            {
+                                projectVersionMetadataResolved =
+                                    metadataResolver.resolveProjectVersion( repositorySession, repoId, groupId,
+                                                                            artifactId, version );
+                                versionMetadata = projectVersionMetadataResolved;
+                                cacheToUpdate = true;
+                            }
+
+                            if ( useCache && cacheToUpdate )
+                            {
+                                versionMetadataCache.put( cacheKey, projectVersionMetadataResolved );
+                            }
+
                         }
                         catch ( MetadataResolutionException e )
                         {
@@ -479,8 +510,8 @@ public class DefaultBrowseService
             {
                 // TODO: what about if we want to see this irrespective of version?
                 references.addAll(
-                    metadataResolver.resolveProjectReferences( repositorySession, repoId, groupId, artifactId, version )
-                );
+                    metadataResolver.resolveProjectReferences( repositorySession, repoId, groupId, artifactId,
+                                                               version ) );
             }
         }
         catch ( MetadataResolutionException e )
@@ -1111,4 +1142,14 @@ public class DefaultBrowseService
                                        n + "." + subNamespaces.iterator().next() );
         }
     }
+
+    public Cache getVersionMetadataCache()
+    {
+        return versionMetadataCache;
+    }
+
+    public void setVersionMetadataCache( Cache versionMetadataCache )
+    {
+        this.versionMetadataCache = versionMetadataCache;
+    }
 }
index 30fd74acc489e8de944e2377e8b7527c5b04aa0d..77d365cbca262839e31385938b976afa7f980023 100644 (file)
     </jaxrs:outFaultInterceptors>
   </jaxrs:server>
 
+  <bean name="browse#versionMetadata" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="userPermissions"/>
+    <property name="timeToIdleSeconds" value="300"/>
+    <property name="timeToLiveSeconds" value="600"/>
+  </bean>
+
 </beans>
\ No newline at end of file