com.github.bootfastconfig.cache.caffeine.MyCaffeineCacheManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boot-fast-config-cache Show documentation
Show all versions of boot-fast-config-cache Show documentation
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);
}
}
}