1 package org.apache.maven.archiva.layer;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import java.util.List;
29 * CachedRepositoryQueryLayer
33 public class CachedRepositoryQueryLayer
34 implements RepositoryQueryLayer
38 public static final double CACHE_HIT_RATIO = 0.5;
40 private RepositoryQueryLayer layer;
42 public CachedRepositoryQueryLayer( RepositoryQueryLayer layer )
46 cache = new Cache( CACHE_HIT_RATIO );
49 public CachedRepositoryQueryLayer( RepositoryQueryLayer layer, Cache cache )
55 public double getCacheHitRate()
57 return cache.getHitRate();
60 public boolean containsArtifact( Artifact artifact )
62 boolean artifactFound = true;
64 String artifactPath = layer.getRepository().pathOf( artifact );
66 if ( cache.get( artifactPath ) == null )
68 artifactFound = layer.containsArtifact( artifact );
71 cache.put( artifactPath, artifactPath );
78 public List getVersions( Artifact artifact )
79 throws RepositoryQueryLayerException
81 List list = (List) cache.get( artifact.getId() );
85 list = layer.getVersions( artifact );
86 cache.put( artifact.getId(), list );
92 public ArtifactRepository getRepository()
94 return layer.getRepository();