name.remal.gradle_plugins.toolkit.cache.ToolkitCacheBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit Show documentation
Show all versions of toolkit Show documentation
Remal Gradle plugins: toolkit: toolkit
package name.remal.gradle_plugins.toolkit.cache;
import static java.lang.Math.max;
import static java.lang.Runtime.getRuntime;
import static lombok.AccessLevel.PRIVATE;
import static name.remal.gradle_plugins.toolkit.cache.ToolkitCacheKeyNormalizer.defaultToolkitCacheKeyNormalizer;
import static name.remal.gradle_plugins.toolkit.cache.ToolkitCacheLastModifiedGetter.defaultToolkitCacheLastModifiedGetter;
import java.lang.ref.SoftReference;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.With;
@NoArgsConstructor
@Getter
@With
@AllArgsConstructor(access = PRIVATE)
public final class ToolkitCacheBuilder {
private ToolkitCacheLoader loader = __ -> {
throw new UnsupportedOperationException("Cache loader is not defined");
};
private ToolkitCacheKeyNormalizer keyNormalizer = defaultToolkitCacheKeyNormalizer();
private ToolkitCacheLastModifiedGetter lastModifiedTimeGetter = defaultToolkitCacheLastModifiedGetter();
private ToolkitCacheReferenceCreator referenceCreator = SoftReference::new;
private int concurrencyLevel = max(4, getRuntime().availableProcessors() * 2);
public ToolkitCache build() {
return new ToolkitCache<>(
loader,
keyNormalizer,
lastModifiedTimeGetter,
referenceCreator,
new ToolkitCacheLocks<>(concurrencyLevel)
);
}
}