public Object get(Object key) { if (log.isDebugEnabled()) {
log.debug("get called (key="+ key +")");
} // 计算hash int hash = hash(key); /**//*
* Start off at the apparently correct bin. If entry is found, we need
* to check after a barrier anyway. If not found, we need a barrier to
* check if we are actually in right bin. So either way, we encounter
* only one barrier unless we need to retry. And we only need to fully
* synchronize if there have been concurrent modifications. */ // 计算在hash表中的位置 Entry[] tab = table; int index = hash & (tab.length -1); // Entry链表中的第一个数据 Entry first = tab[index];
Entry e = first; for (;;) { if (e ==null) { // If key apparently not there, check to // make sure this was a valid read // key没找到,再次查看hash表确定是否真的找不到了 tab = getTableForReading(); if (first == tab[index]) { // Not in the table, try persistence // 试着在持久化处找 Object value = persistRetrieve(key); if (value !=null) { // Update the map, but don't persist the data // 在持久化处找到数据的话需要更新hash表,但不去重新持久化 put(key, value, false);
} return value;
}else{ // Wrong list -- must restart traversal at new first e = first = tab[index = hash & (tab.length -1)];
}
} // checking for pointer equality first wins in most applications elseif ((key == e.key) || ((e.hash == hash) && key.equals(e.key))) {// 找到了数据 Object value = e.value; if (value !=null) { if (NULL.equals(value)) { // Memory cache disable, use disk // 需要去缓存找数据 value = persistRetrieve(e.key); if (value !=null) { // 调用回调 itemRetrieved(key);
} return value; // fix [CACHE-13] }else{ // 调用回调 itemRetrieved(key); return value;
}
}