1 package org.apache.maven.repository.reporting;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.repository.ArtifactRepository;
21 import org.apache.maven.artifact.repository.metadata.Metadata;
22 import org.apache.maven.artifact.repository.metadata.Snapshot;
28 public class CachedRepositoryQueryLayer
29 extends AbstractRepositoryQueryLayer
33 private static final double CACHE_HIT_RATIO = 0.5;
36 public CachedRepositoryQueryLayer( ArtifactRepository repository )
38 this.repository = repository;
40 cache = new Cache( CACHE_HIT_RATIO );
43 public double getCacheHitRate()
45 return cache.getHitRate();
48 public boolean containsArtifact( Artifact artifact )
50 boolean artifactFound = true;
52 String artifactPath = repository.getBasedir() + "/" + repository.pathOf( artifact );
54 if ( cache.get( artifactPath ) == null )
56 artifactFound = super.containsArtifact( artifact );
59 cache.put( artifactPath, artifactPath );
66 public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
68 boolean artifactFound = true;
70 String path = getSnapshotArtifactRepositoryPath( artifact, snapshot );
72 if ( cache.get( path ) == null )
74 artifactFound = super.containsArtifact( artifact, snapshot );
77 cache.put( path, path );
85 * Override method to utilize the cache
87 protected Metadata getMetadata( Artifact artifact )
88 throws RepositoryQueryLayerException
90 Metadata metadata = (Metadata) cache.get( artifact.getId() );
92 if ( metadata == null )
94 metadata = super.getMetadata( artifact );
95 cache.put( artifact.getId(), metadata );