package com.atlassian.bitbucket.scm.context;

import com.atlassian.bitbucket.repository.Repository;

/**
 * An abstraction over caching {@link Repository} instances for reuse.
 * <p>
 * This abstraction primarily exists to allow different test execution listeners to share interaction with the cache.
 */
public interface RepositoryCache {

    /**
     * Retrieves the cached {@link Repository} for the provided location, or {@code null} if no cached repository is
     * found.
     * 
     * @param location the resource location
     * @return a previously-unpacked repository, or {@code null}
     */
    Repository getRepository(String location);

    /**
     * Removes any {@link Repository} cached for the provided location.
     * 
     * @param location the resource location
     */
    void removeRepository(String location);

    /**
     * Caches the provided {@link Repository}, indexed by the specified location.
     * <p>
     * Note: If the new repository evicts/overwrites a previously-cached repository it is not an error.
     *
     * @param location   the resource location
     * @param repository the unpacked repository to cache
     */
    void setRepository(String location, Repository repository);
}
