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  /**
14   * Caches auxiliary data used during repository access like already processed metadata. The data in the cache is meant
15   * for exclusive consumption by the repository system and is opaque to the cache implementation. <strong>Note:</strong>
16   * Actual cache implementations must be thread-safe.
17   * 
18   * @see RepositorySystemSession#getCache()
19   */
20  public interface RepositoryCache
21  {
22  
23      /**
24       * Puts the specified data into the cache. It is entirely up to the cache implementation how long this data will be
25       * kept before being purged, i.e. callers must not make any assumptions about the lifetime of cached data.
26       * <p>
27       * <em>Warning:</em> The cache will directly save the provided reference. If the cached data is mutable, i.e. could
28       * be modified after being put into the cache, the caller is responsible for creating a copy of the original data
29       * and store the copy in the cache.
30       * 
31       * @param session The repository session during which the cache is accessed, must not be {@code null}.
32       * @param key The key to use for lookup of the data, must not be {@code null}.
33       * @param data The data to store in the cache, may be {@code null}.
34       */
35      void put( RepositorySystemSession session, Object key, Object data );
36  
37      /**
38       * Gets the specified data from the cache.
39       * <p>
40       * <em>Warning:</em> The cache will directly return the saved reference. If the cached data is to be modified after
41       * its retrieval, the caller is responsible to create a copy of the returned data and use this instead of the cache
42       * record.
43       * 
44       * @param session The repository session during which the cache is accessed, must not be {@code null}.
45       * @param key The key to use for lookup of the data, must not be {@code null}.
46       * @return The requested data or {@code null} if none was present in the cache.
47       */
48      Object get( RepositorySystemSession session, Object key );
49  
50  }