001/**
002 *
003 * Copyright © 2014-2023 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://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.jxmpp.util.cache;
018
019/**
020 * This is jXMPP's cache interface.
021 *
022 * @param <K> the type of the keys of this cache.
023 * @param <V> the type of the values this cache caches.
024 */
025public interface Cache<K, V> {
026
027        /**
028         * Put a value in the cache.
029         *
030         * @param key the key of the value.
031         * @param value the value.
032         * @return the previous value or {@code null}.
033         */
034        V put(K key, V value);
035
036        /**
037         * Returns the value of the specified key, or {@code null}.
038         *
039         * @param key the key.
040         * @return the value found in the cache, or {@code null}.
041         */
042        V lookup(K key);
043
044        /**
045         * Return the maximum cache Size.
046         *
047         * @return the maximum cache size.
048         */
049        int getMaxCacheSize();
050
051        /**
052         * Set the maximum cache size.
053         * @param size the new maximum cache size.
054         */
055        void setMaxCacheSize(int size);
056}