View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether;
20  
21  import java.util.function.Supplier;
22  
23  /**
24   * Caches auxiliary data used during repository access like already processed metadata. The data in the cache is meant
25   * for exclusive consumption by the repository system and is opaque to the cache implementation. <strong>Note:</strong>
26   * Actual cache implementations must be thread-safe.
27   *
28   * @see RepositorySystemSession#getCache()
29   * @noimplement This interface is not intended to be implemented by clients.
30   * @noextend This interface is not intended to be extended by clients.
31   */
32  public interface RepositoryCache {
33  
34      /**
35       * Puts the specified data into the cache. It is entirely up to the cache implementation how long this data will be
36       * kept before being purged, i.e. callers must not make any assumptions about the lifetime of cached data.
37       * <p>
38       * <em>Warning:</em> The cache will directly save the provided reference. If the cached data is mutable, i.e. could
39       * be modified after being put into the cache, the caller is responsible for creating a copy of the original data
40       * and store the copy in the cache.
41       *
42       * @param session The repository session during which the cache is accessed, must not be {@code null}.
43       * @param key The key to use for lookup of the data, must not be {@code null}.
44       * @param data The data to store in the cache, may be {@code null}.
45       */
46      void put(RepositorySystemSession session, Object key, Object data);
47  
48      /**
49       * Gets the specified data from the cache.
50       * <p>
51       * <em>Warning:</em> The cache will directly return the saved reference. If the cached data is to be modified after
52       * its retrieval, the caller is responsible to create a copy of the returned data and use this instead of the cache
53       * record.
54       *
55       * @param session The repository session during which the cache is accessed, must not be {@code null}.
56       * @param key The key to use for lookup of the data, must not be {@code null}.
57       * @return The requested data or {@code null} if none was present in the cache.
58       */
59      Object get(RepositorySystemSession session, Object key);
60  
61      /**
62       * Retrieve or compute the data associated with the specified key.
63       *
64       * @param key The key for which to retrieve the session data, must not be {@code null}.
65       * @param supplier The supplier will compute the new value, must not be {@code null}.
66       * @return The cache data associated with the key.
67       * @since 2.0.0
68       */
69      Object computeIfAbsent(RepositorySystemSession session, Object key, Supplier<Object> supplier);
70  }