com.bumptech.glide.provider.ModelToResourceClassCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of glide Show documentation
Show all versions of glide Show documentation
A fast and efficient image loading library for Android focused on smooth scrolling.
package com.bumptech.glide.provider;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;
import com.bumptech.glide.util.MultiClassKey;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
* Maintains a cache of Model + Resource class to a set of registered resource classes that are
* subclasses of the resource class that can be decoded from the model class.
*/
public class ModelToResourceClassCache {
private final AtomicReference resourceClassKeyRef = new AtomicReference<>();
private final ArrayMap>> registeredResourceClassCache =
new ArrayMap<>();
@Nullable
public List> get(
@NonNull Class> modelClass,
@NonNull Class> resourceClass,
@NonNull Class> transcodeClass) {
MultiClassKey key = resourceClassKeyRef.getAndSet(null);
if (key == null) {
key = new MultiClassKey(modelClass, resourceClass, transcodeClass);
} else {
key.set(modelClass, resourceClass, transcodeClass);
}
final List> result;
synchronized (registeredResourceClassCache) {
result = registeredResourceClassCache.get(key);
}
resourceClassKeyRef.set(key);
return result;
}
public void put(
@NonNull Class> modelClass,
@NonNull Class> resourceClass,
@NonNull Class> transcodeClass,
@NonNull List> resourceClasses) {
synchronized (registeredResourceClassCache) {
registeredResourceClassCache.put(
new MultiClassKey(modelClass, resourceClass, transcodeClass), resourceClasses);
}
}
public void clear() {
synchronized (registeredResourceClassCache) {
registeredResourceClassCache.clear();
}
}
}