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