001/**
002 * Copyright (c) 2012, 2014, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016package org.javamoney.moneta.loader.internal;
017
018import java.io.IOException;
019
020/**
021 * Abstraction of a {@link ResourceCache}. By default a file cache is used:
022 * {@link DefaultResourceCache}.
023 *
024 * @author Anatole Tresch
025 */
026public interface ResourceCache {
027    /**
028     * Write the given byte array to the internal store and register it on the
029     * given resource ID.
030     *
031     * @param resourceId
032     *            the resource id, never {@code null}.
033     * @param data
034     *            the data
035     * @throws IOException
036     *             when an IO error occurs.
037     */
038    void write(String resourceId, byte[] data);
039
040    /**
041     * Allows to query if a resource with the given id is present within the
042     * local cache.
043     *
044     * @param resourceId
045     *            The resourceId
046     * @return true, if the resource was found in the local cache.
047     */
048    boolean isCached(String resourceId);
049
050    /**
051     * Reads the given resource, identified by the resourceId, from the cache.
052     *
053     * @param resourceId
054     *            the resource id.
055     * @return the data of the resource.
056     * @throws IllegalArgumentException
057     *             if no such resource is existing.
058     */
059    byte[] read(String resourceId);
060
061    /**
062     * Remove a cache entry.
063     * @param resourceId the resource idntifer, not null.
064     */
065    void clear(String resourceId);
066}