improve configuration for guava cache

This commit is contained in:
Sebastian Sdorra
2013-03-25 10:53:01 +01:00
parent 3dfa6d4fc1
commit 09d4ea87af
5 changed files with 208 additions and 84 deletions

View File

@@ -34,6 +34,7 @@ package sonia.scm.cache;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.Maps;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,6 +49,7 @@ import java.util.Map;
*
* @author Sebastian Sdorra
*/
@Singleton
public class GuavaCacheManager implements CacheManager
{
@@ -57,6 +59,25 @@ public class GuavaCacheManager implements CacheManager
private static final Logger logger =
LoggerFactory.getLogger(GuavaCacheManager.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public GuavaCacheManager()
{
CacheConfigurationReader reader = new CacheConfigurationReader();
CacheManagerConfiguration config = reader.read();
defaultConfiguration = config.getDefaultCache();
for (NamedCacheConfiguration ncc : config.getCaches())
{
cacheMap.put(ncc.getName(), new GuavaCache(ncc));
}
}
//~--- methods --------------------------------------------------------------
/**
@@ -105,7 +126,7 @@ public class GuavaCacheManager implements CacheManager
logger.debug(
"cache {} does not exists, creating a new instance from default configuration: {}",
name, defaultConfiguration);
cache = new GuavaCache<K, V>(defaultConfiguration);
cache = new GuavaCache<K, V>(defaultConfiguration, name);
cacheMap.put(name, cache);
}
@@ -118,5 +139,5 @@ public class GuavaCacheManager implements CacheManager
private Map<String, GuavaCache> cacheMap = Maps.newConcurrentMap();
/** Field description */
private NamedCacheConfiguration defaultConfiguration;
private CacheConfiguration defaultConfiguration;
}