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

com.github.mizool.technology.jcache.timeouting.TimeoutingCacheManager Maven / Gradle / Ivy

package com.github.mizool.technology.jcache.timeouting;

import java.util.concurrent.Callable;

import javax.cache.Cache;
import javax.cache.configuration.Configuration;
import jakarta.inject.Inject;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

import com.github.mizool.core.NonDefault;
import com.github.mizool.technology.jcache.common.AbstractDelegatingCacheManager;

@Slf4j
@NonDefault
public class TimeoutingCacheManager extends AbstractDelegatingCacheManager
{
    private final TimeoutingExecutor timeoutingExecutor;

    @Inject
    public TimeoutingCacheManager(@NonNull TimeoutingExecutor timeoutingExecutor)
    {
        this.timeoutingExecutor = timeoutingExecutor;
    }

    @Override
    public > Cache createCache(String cacheName, C configuration)
        throws IllegalArgumentException
    {
        Callable> cacheCallable = () -> super.createCache(cacheName, configuration);
        return getTimeoutingCache(cacheCallable);
    }

    @Override
    public  Cache getCache(String cacheName)
    {
        Callable> cacheCallable = () -> super.getCache(cacheName);
        return getTimeoutingCache(cacheCallable);
    }

    private  Cache getTimeoutingCache(Callable> cacheCallable)
    {
        Cache result = null;

        Cache cache = timeoutingExecutor.execute(cacheCallable);
        if (cache != null)
        {
            result = new TimeoutingCache<>(cache, timeoutingExecutor);
        }

        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy