001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether;
020
021/**
022 * Caches auxiliary data used during repository access like already processed metadata. The data in the cache is meant
023 * for exclusive consumption by the repository system and is opaque to the cache implementation. <strong>Note:</strong>
024 * Actual cache implementations must be thread-safe.
025 *
026 * @see RepositorySystemSession#getCache()
027 */
028public interface RepositoryCache {
029
030    /**
031     * Puts the specified data into the cache. It is entirely up to the cache implementation how long this data will be
032     * kept before being purged, i.e. callers must not make any assumptions about the lifetime of cached data.
033     * <p>
034     * <em>Warning:</em> The cache will directly save the provided reference. If the cached data is mutable, i.e. could
035     * be modified after being put into the cache, the caller is responsible for creating a copy of the original data
036     * and store the copy in the cache.
037     *
038     * @param session The repository session during which the cache is accessed, must not be {@code null}.
039     * @param key The key to use for lookup of the data, must not be {@code null}.
040     * @param data The data to store in the cache, may be {@code null}.
041     */
042    void put(RepositorySystemSession session, Object key, Object data);
043
044    /**
045     * Gets the specified data from the cache.
046     * <p>
047     * <em>Warning:</em> The cache will directly return the saved reference. If the cached data is to be modified after
048     * its retrieval, the caller is responsible to create a copy of the returned data and use this instead of the cache
049     * record.
050     *
051     * @param session The repository session during which the cache is accessed, must not be {@code null}.
052     * @param key The key to use for lookup of the data, must not be {@code null}.
053     * @return The requested data or {@code null} if none was present in the cache.
054     */
055    Object get(RepositorySystemSession session, Object key);
056}