    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.jexl3;
    018
    019import java.util.Collection;
    020import java.util.Collections;
    021import java.util.Map;
    022
    023/**
    024 * Caching script or template interface.
    025 *
    026 * @param <K> source
    027 * @param <V> script or template
    028 */
    029public interface JexlCache<K, V> {
    030
    031    /**
    032     * Returns the cache capacity, the maximum number of elements it can contain.
    033     *
    034     * @return the cache capacity
    035     */
    036    int capacity();
    037
    038    /**
    039     * Clears the cache.
    040     */
    041    void clear();
    042
    043    /**
    044     * Produces the cache entry set.
    045     *
    046     * <p>
    047     * For implementations testing only
    048     * </p>
    049     *
    050     * @return the cache entry list
    051     */
    052    default Collection<Map.Entry<K, V>> entries() {
    053        return Collections.emptyList();
    054    }
    055
    056    /**
    057     * Gets a value from this cache.
    058     *
    059     * @param key the cache entry key
    060     * @return the cache entry value
    061     */
    062    V get(K key);
    063
    064    /**
    065     * Puts a value in this cache.
    066     *
    067     * @param key    the cache entry key
    068     * @param script the cache entry value
    069     * @return the previously associated value if any
    070     */
    071    V put(K key, V script);
    072
    073    /**
    074     * Returns the cache size, the actual number of elements it contains.
    075     *
    076     * @return the cache size
    077     */
    078    int size();
    079
    080    /**
    081     * A cached reference.
    082     */
    083    interface Reference {
    084
    085        /**
    086         * Gets the referenced object.
    087         *
    088         * @return the referenced object
    089         */
    090        Object getCache();
    091
    092        /**
    093         * Sets the referenced object.
    094         *
    095         * @param cache the referenced object
    096         */
    097        void setCache(Object cache);
    098    }
    099}