keycloakjar.com.github.benmanes.caffeine.cache.AsyncCacheLoader Maven / Gradle / Ivy
Show all versions of camunda-bpm-identity-keycloak-all Show documentation
/*
* Copyright 2016 Ben Manes. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.benmanes.caffeine.cache;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Computes or retrieves values asynchronously, based on a key, for use in populating a
* {@link AsyncLoadingCache}.
*
* Most implementations will only need to implement {@link #asyncLoad}. Other methods may be
* overridden as desired.
*
* Usage example:
*
{@code
* AsyncCacheLoader loader = (key, executor) ->
* createExpensiveGraphAsync(key, executor);
* AsyncLoadingCache cache = Caffeine.newBuilder().buildAsync(loader);
* }
*
* @author [email protected] (Ben Manes)
*/
@FunctionalInterface
public interface AsyncCacheLoader {
/**
* Asynchronously computes or retrieves the value corresponding to {@code key}.
*
* @param key the non-null key whose value should be loaded
* @param executor the executor with which the entry is asynchronously loaded
* @return the future value associated with {@code key}
*/
@NonNull
CompletableFuture asyncLoad(@NonNull K key, @NonNull Executor executor);
/**
* Asynchronously computes or retrieves the values corresponding to {@code keys}. This method is
* called by {@link AsyncLoadingCache#getAll}.
*
* If the returned map doesn't contain all requested {@code keys} then the entries it does contain
* will be cached and {@code getAll} will return the partial results. If the returned map contains
* extra keys not present in {@code keys} then all returned entries will be cached, but only the
* entries for {@code keys} will be returned from {@code getAll}.
*
* This method should be overridden when bulk retrieval is significantly more efficient than many
* individual lookups. Note that {@link AsyncLoadingCache#getAll} will defer to individual calls
* to {@link AsyncLoadingCache#get} if this method is not overridden.
*
* @param keys the unique, non-null keys whose values should be loaded
* @param executor the executor with which the entries are asynchronously loaded
* @return a future containing the map from each key in {@code keys} to the value associated with
* that key; may not contain null values
*/
@NonNull
default CompletableFuture