aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2014-03-27 06:02:33 +0000
committerOlivier Lamy <olamy@apache.org>2014-03-27 06:02:33 +0000
commit90d0b07393e106abcc91dcad592a03c9186312b9 (patch)
tree9b4e40f33f669342b3d637ae4c1aba91aed2df5e /archiva-modules
parent1011a321c84ab48353a12fa809297f5879358ade (diff)
downloadarchiva-90d0b07393e106abcc91dcad592a03c9186312b9.tar.gz
archiva-90d0b07393e106abcc91dcad592a03c9186312b9.zip
add a bit of caching here at least for released version
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1582203 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java51
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml11
2 files changed, 57 insertions, 5 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
index b16d70440..348a2dd51 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
@@ -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;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
index 30fd74acc..77d365cbc 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
@@ -85,4 +85,15 @@
</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