Safely Handling Concurrent Memcache Updates in AppEngine

落爺英雄遲暮 提交于 2019-12-05 15:12:52

I need to understand something about your code:
First why are you checking if count != null? doesn't oldCountIdValue == null means that count == null and the other way around: if oldCountIdValue != null then count != null

if so then the code should be:

IdentifiableValue oldCountIdValue = mc.getIdentifiable( cacheKey );
if (oldCountIdValue != null) {
   return ( Long ) oldCountIdValue.getValue();
}

Long result = new Long( q.count() );
mc.putIfUntouched( cacheKey, oldCountValue, result );
return result;

if putIfUntouched returns null, it means that your result variable is not accurate anymore, you can do the following: ignore and return your current result or load the result from the cache.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!