com.android.ide.common.caching.CreatingCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-common Show documentation
Show all versions of sdk-common Show documentation
sdk-common library used by other Android tools libraries.
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.android.ide.common.caching;
import static com.google.common.base.Preconditions.checkArgument;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.annotations.VisibleForTesting;
import com.android.annotations.concurrency.GuardedBy;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
/**
* A cache that handles creating the values when they are not present in the map.
*
* Calls to {@link #get(Object)} returns the value, calling into {@link ValueFactory} if it
* was not created. If the creation takes a long time, other threads can still query the cache
* for the same or different keys. Calls for the same key will block until the value has been
* created. Calls for different keys will return right away if the key is available.
*
* This is very similar to Guava's LoadingCache, without the automated clean-up based on size
* or time.
* This is extracted from the PreDexCache of the Gradle plugin which has different requirements
* (reloading cached info from disk)
*
* This class is thread-safe.
*
* TODO Move PreDexCache to be based on this.
*
*/
public class CreatingCache {
@GuardedBy("this")
private final Map
© 2015 - 2024 Weber Informatics LLC | Privacy Policy