注:
1、这个方法主要是从取样节点中查找需要淘汰的缓存。
2、最关键的就是调用compare这个方法其实就是调用的上面那三个策略实现的方法来找个可以淘汰的缓存节点。
那么接下来我们看一下淘汰缓存的生命周期流程是怎么样的。

12.2 EhcacheManager类解析
这个类是2.10.2版本的最核心类,初始化、创建缓存、获取缓存都会用到这个类,这个类里面有几十个方法非常多,我们会按照类别分别进行介绍,先看其构造方法吧。

先看方法CacheManager()默认的情况代码如下:
public CacheManager() throws CacheException {
// default config will be done
status = Status.STATUS_UNINITIALISED;
init(null, null, null, null);
}
Status.STATUS_UNINITIALISED这句的意思是缓存未被初始化,在构造方法里面要设定一个初始状态。
我们接着看init方法,这个方法是有别于其他构造方法的,因为默认的情况下这个方法的参数全传null值,这就意味着使用ehcache自己默认的配置了。
代码如下:
protected synchronized void init(Configuration initialConfiguration, String configurationFileName, URL configurationURL,
InputStream configurationInputStream) {
Configuration configuration;
if (initialConfiguration == null) {
configuration = parseConfiguration(configurationFileName, configurationURL, configurationInputStream);
} else {
configuration = initialConfiguration;
}
assertManagementRESTServiceConfigurationIsCorrect(configuration);
assertNoCacheManagerExistsWithSameName(configuration);
try {
doInit(configuration);
} catch (Throwable t) {
if (terracottaClient != null) {
terracottaClient.shutdown();
}
if (statisticsExecutor != null) {
statisticsExecutor.shutdown();
}
if (featuresManager != null) {
featuresManager.dispose();
}
if (diskStorePathManager != null) {
diskStorePathManager.releaseLock();
}
if (cacheManagerTimer != null) {
cacheManagerTimer.cancel();
cacheManagerTimer.purge();
}
synchronized (CacheManager.class) {
final String name = CACHE_MANAGERS_REVERSE_MAP.remove(this);
CACHE_MANAGERS_MAP.remove(name);
}
ALL_CACHE_MANAGERS.remove(this);
if (t instanceof CacheException) {
throw (CacheException) t;
} else {
throw new CacheException(t);
}
}
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25691-11.html
当然北洋用的