All Downloads are FREE. Search and download functionalities are using the official Maven repository.

name.remal.gradle_plugins.toolkit.cache.ToolkitCacheBuilder Maven / Gradle / Ivy

There is a newer version: 0.64.11
Show newest version
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)
        );
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy