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.internal.loader;
017
018
019/**
020 * Abstraction of a {@link ResourceCache}. By default a file cache is used:
021 * {@link DefaultResourceCache}.
022 *
023 * @author Anatole Tresch
024 */
025public interface ResourceCache {
026    /**
027     * Write the given byte array to the format store and register it on the
028     * given resource ID.
029     *
030     * @param resourceId
031     *            the resource id, never {@code null}.
032     * @param data
033     *            the data
034     */
035    void write(String resourceId, byte[] data);
036
037    /**
038     * Allows to query if a resource with the given id is present within the
039     * local cache.
040     *
041     * @param resourceId
042     *            The resourceId
043     * @return true, if the resource was found in the local cache.
044     */
045    boolean isCached(String resourceId);
046
047    /**
048     * Reads the given resource, identified by the resourceId, from the cache.
049     *
050     * @param resourceId
051     *            the resource id.
052     * @return the data of the resource.
053     * @throws IllegalArgumentException
054     *             if no such resource is existing.
055     */
056    byte[] read(String resourceId);
057
058    /**
059     * Remove a cache entry.
060     * @param resourceId the resource identifier, not null.
061     */
062    void clear(String resourceId);
063}