知识卡片
先查存在仍可能读取缺失
示例先memcache.contains(cacheKey)再get(cacheKey)。缓存可能在两次调用之间被淘汰,因此前一步为真不保证后一步返回对象。此为依据可淘汰缓存与示例控制流的推论;读路径仍须把get的缺失结果纳入回源分支,不能因contains成立就直接返回null。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第2章 创建一个应用程序 开发一个Java应用程序 · 连续片段5 · 查看原书依据
if(memcache.contains(cacheKey)){ userPrefs=(UserPrefs)memcache.get(cacheKey); return userPrefs; } //If the UserPrefs object isn't in memcach
参考来源
- 位置:《GAE编程指南》第02章《开发一个Java应用程序 · 连续片段5》(来源项目book-sources;源文件:extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part2847.html,spine2934)
- 结论依据:该小节的操作、示例与讨论支持本卡所述机制及条件;具体接口、语法和命令限定于本书2010年的早期Google App Engine环境,迁移到其他版本须另行核验。
- 原始内容:if(memcache.contains(cacheKey)){ userPrefs=(UserPrefs)memcache.get(cacheKey); return userPrefs; } //If the UserPrefs object isn't in memcach