「已注销」 2022-03-02 11:06 采纳率: 66.7%
浏览 34

【spring三级缓存】spring二级缓存put问题

问题遇到的现象和发生背景

【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;
}
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

  • CSDN专家-sinJack 2022-03-02 14:15
    关注

    执行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);
    
    评论

报告相同问题?

问题事件

  • 创建了问题 3月2日

悬赏问题

  • ¥15 如何让usb软件在电脑拔插无记录
  • ¥15 ecology9的待办推送外部系统
  • ¥15 Mplus跑出来的数据只有原数据的一半
  • ¥15 vue项目添加全局处理解决一些开发问题
  • ¥40 微信小程序前后端交互
  • ¥50 数据预处理(大量数据)
  • ¥15 多设备数据融合可视化显示控制
  • ¥15 公众号关键词自动回复超链接
  • ¥18 help me! 希望大家来看看 吉~
  • ¥15 C++显示超限兔子集结