View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2010, 2014 Sonatype, Inc.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *    Sonatype, Inc. - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.aether;
12  
13  import java.util.Map;
14  import java.util.concurrent.ConcurrentHashMap;
15  
16  /**
17   * A simplistic repository cache backed by a thread-safe map. The simplistic nature of this cache makes it only suitable
18   * for use with short-lived repository system sessions where pruning of cache data is not required.
19   */
20  public final class DefaultRepositoryCache
21      implements RepositoryCache
22  {
23  
24      private final Map<Object, Object> cache = new ConcurrentHashMap<Object, Object>( 256 );
25  
26      public Object get( RepositorySystemSession session, Object key )
27      {
28          return cache.get( key );
29      }
30  
31      public void put( RepositorySystemSession session, Object key, Object data )
32      {
33          if ( data != null )
34          {
35              cache.put( key, data );
36          }
37          else
38          {
39              cache.remove( key );
40          }
41      }
42  
43  }