From 90d0b07393e106abcc91dcad592a03c9186312b9 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 27 Mar 2014 06:02:33 +0000 Subject: 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 --- .../rest/services/DefaultBrowseService.java | 51 +++++++++++++++++++--- .../src/main/resources/META-INF/spring-context.xml | 11 +++++ 2 files changed, 57 insertions(+), 5 deletions(-) (limited to 'archiva-modules') 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 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 @@ + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3