<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-common</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus.cache</groupId>
+ <artifactId>plexus-cache-api</artifactId>
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-ehcache</artifactId>
- <version>1.0-alpha-1</version>
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
</dependency>
- <!-- TEST DEPS -->
- <dependency>
- <groupId>org.codehaus.plexus.cache</groupId>
- <artifactId>plexus-cache-hashmap</artifactId>
- <version>1.0-alpha-1</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
<plugins>
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.cache.Cache;
+import org.codehaus.plexus.cache.CacheException;
+import org.codehaus.plexus.cache.CacheHints;
+import org.codehaus.plexus.cache.factory.CacheFactory;
import java.util.List;
* CachedRepositoryQueryLayer - simple wrapper around another non-cached Repository Query Layer.
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.layer.RepositoryQueryLayer" role-hint="cached"
*/
public class CachedRepositoryQueryLayer
implements RepositoryQueryLayer
{
- /**
- * @plexus.requirement role-hint="repository-query"
- */
private Cache cache;
- /**
- * @plexus.requirement
- */
private RepositoryQueryLayer layer;
-
- public CachedRepositoryQueryLayer()
+
+ public CachedRepositoryQueryLayer( RepositoryQueryLayer layer )
+ throws RepositoryQueryLayerException
{
+ this.layer = layer;
+ String repoId = layer.getRepository().getId();
+ CacheHints hints = new CacheHints();
+ hints.setName( repoId );
+ hints.setOverflowToDisk( false );
+ try
+ {
+ this.cache = CacheFactory.getInstance().getCache( repoId, hints );
+ }
+ catch ( CacheException e )
+ {
+ throw new RepositoryQueryLayerException( "Unable to initialize cache: " + e.getMessage(), e );
+ }
}
public boolean containsArtifact( Artifact artifact )
* DefaultRepositoryQueryLayer
*
* @version $Id$
+ * @plexus.component role="org.apache.maven.archiva.layer.RepositoryQueryLayer" role-hint="default"
*/
public class DefaultRepositoryQueryLayer
implements RepositoryQueryLayer
{
protected ArtifactRepository repository;
-
+
public DefaultRepositoryQueryLayer( ArtifactRepository repository )
{
this.repository = repository;
* under the License.
*/
-
/**
* CachedRepositoryQueryLayerTest
*
{
super.setUp();
- queryLayer = (RepositoryQueryLayer) lookup( RepositoryQueryLayer.ROLE, "test-cached" );
+ RepositoryQueryLayer defaultLayer = new DefaultRepositoryQueryLayer( repository );
+
+ queryLayer = new CachedRepositoryQueryLayer( defaultLayer );
}
public void testUseFileCache()
+++ /dev/null
-<?xml version="1.0" ?>
-
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- -->
-
-<component-set>
- <components>
- <component>
- <role>org.apache.maven.archiva.layer.RepositoryQueryLayer</role>
- <role-hint>test-cached</role-hint>
- <implementation>org.apache.maven.archiva.layer.CachedRepositoryQueryLayer</implementation>
- <description>CachedRepositoryQueryLayer - simple wrapper around another non-cached Repository Query Layer.</description>
- <requirements>
- <requirement>
- <role>org.codehaus.plexus.cache.Cache</role>
- <role-hint>test-repository-query</role-hint>
- <field-name>cache</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.archiva.layer.RepositoryQueryLayer</role>
- <field-name>layer</field-name>
- </requirement>
- </requirements>
- </component>
-
- <component>
- <role>org.codehaus.plexus.cache.Cache</role>
- <role-hint>test-repository-query</role-hint>
- <implementation>org.codehaus.plexus.cache.hashmap.HashMapCache</implementation>
- <configuration>
- <cache-hit-ratio>1.0</cache-hit-ratio>
- <cache-max-size>0</cache-max-size>
- </configuration>
- </component>
- </components>
-</component-set>
\ No newline at end of file