001package ca.uhn.fhir.sl.cache;
002
003/*-
004 * #%L
005 * HAPI FHIR - ServiceLoaders - Caching API
006 * %%
007 * Copyright (C) 2014 - 2023 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import java.util.Map;
024import java.util.function.Function;
025
026/**
027 * This interface is a blend between
028 * <a href="https://github.com/ben-manes/caffeine">Caffeine's Cache</a> and
029 * <a href="https://github.com/google/guava/wiki/CachesExplained"></a>Guava's Cache</a>.
030 *
031 * Please check their documentation for information in the methods below.
032 */
033public interface Cache<K, V> {
034        V getIfPresent(K key);
035
036        V get(K key, Function<? super K, ? extends V> mappingFunction);
037
038        Map<K, V> getAllPresent(Iterable<? extends K> keys);
039
040        void put(K key, V value);
041
042        void putAll(Map<? extends K, ? extends V> map);
043
044        void invalidate(K key);
045
046        void invalidateAll(Iterable<? extends K> keys);
047
048        void invalidateAll();
049
050        long estimatedSize();
051
052        void cleanUp();
053}