【spring三级缓存】spring二级缓存只有一个put的地方,而且是在get才去put,那get一定是get不到的,那get存在的意义是什么?
@Nullable
protected Object getSingleton(String beanName, boolean allowEarlyReference) {
Object singletonObject = this.singletonObjects.get(beanName);
if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {
synchronized (this.singletonObjects) {
singletonObject = this.earlySingletonObjects.get(beanName);
if (singletonObject == null && allowEarlyReference) {
ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);
if (singletonFactory != null) {
singletonObject = singletonFactory.getObject();
this.earlySingletonObjects.put(beanName, singletonObject);
this.singletonFactories.remove(beanName);
}
}
}
}
return singletonObject;
}
执行getSingleton,去单例缓存池中获取bean。
Object singletonObject = this.singletonObjects.get(beanName);
然后判断是否获取到,没获取到就去二级缓存中获取
if (singletonObject == null && isSingletonCurrentlyInCreation(beanName))
singletonObject = this.earlySingletonObjects.get(beanName);
二级缓存中也没有获取到,就去三级缓存,实例工厂缓存中获取,allowEarlyReference是是否允许从实例工厂缓存中获取实例,默认true
if (singletonObject == null && allowEarlyReference)
ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);