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.concurrent.ExecutionException;
025import java.util.function.Function;
026
027/**
028 * This interface is a blend between
029 * <a href="https://github.com/ben-manes/caffeine">Caffeine's Cache</a> and
030 * <a href="https://github.com/google/guava/wiki/CachesExplained"></a>Guava's Cache</a>.
031 *
032 * Please check their documentation for information in the methods below.
033 */
034public interface Cache<K, V> {
035    V getIfPresent(K key);
036
037    V get(K key, Function<? super K, ? extends V> mappingFunction);
038
039    Map<K, V> getAllPresent(Iterable<? extends K> keys);
040
041    void put(K key, V value);
042
043    void putAll(Map<? extends K, ? extends V> map);
044
045    void invalidate(K key);
046
047    void invalidateAll(Iterable<? extends K> keys);
048
049    void invalidateAll();
050
051    long estimatedSize();
052
053    void cleanUp();
054}