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

com.github.bootfastconfig.cache.caffeine.MyCaffeineCacheManager Maven / Gradle / Ivy

Go to download

Parent pom providing dependency and plugin management for applications built with Maven

The newest version!
package com.github.bootfastconfig.cache.caffeine;

import com.github.bootfastconfig.cache.CacheBuilder;
import org.springframework.cache.Cache;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.caffeine.CaffeineCacheManager;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;

/**
 * @author mister
 */
public class MyCaffeineCacheManager extends CaffeineCacheManager implements Consumer> {

    private final ConcurrentMap cacheMap = new ConcurrentHashMap<>(16);


    MyCaffeineCacheManager() {

    }


    @Override
    public Cache getCache(String name) {
        Cache cache = this.cacheMap.get(name);
        if (cache == null) {
            return super.getCache(name);
        }
        return cache;
    }

    @Override
    public void accept(CacheBuilder caffeineCacheCacheBuilder) {
        if (caffeineCacheCacheBuilder == null) return;
        synchronized (this.cacheMap) {
            CaffeineCache builder = caffeineCacheCacheBuilder.get();
            cacheMap.put(builder.getName(), builder);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy