function _dmemcache_get_multi_2nd_chance_ascii_auth in Memcache API and Integration 7
Checks if cache items are really missing or only missing ascii authentication.
This is essentially a cache miss and hence we would be going into a heavy code path anyway, therefore it is performance wise okay to check a special key that exists on all memcache servers to see if this is:
a) real cache miss (where we need to do all the hard work) b) ascii authentication failure (where we just need to login and then can hopefully have a cache hit)
The edge case of the special lifetime key not existing is treated as a real cache miss.
This is justified by the case that most likely memcache was just restarted (else the lifetime key would not be missing) and hence the real cache request likely would have been a real cache miss anyway.
Parameters
array $results: The results array to check for a 2nd chance.
object $mc: The memcache object.
1 call to _dmemcache_get_multi_2nd_chance_ascii_auth()
- dmemcache_get_multi in ./
dmemcache.inc - Retrieve multiple values from the cache.
File
- ./
dmemcache.inc, line 1454 - A memcache API for Drupal.
Code
function _dmemcache_get_multi_2nd_chance_ascii_auth($results, $mc) {
// Cache misses are very costly: Find out, if any servers need authentication.
$servers = array();
foreach ($results as $full_key => $value) {
if (!empty($value)) {
continue;
}
$s = $mc
->getServerByKey($full_key);
$server_key = $s['host'] . ':' . $s['port'];
$servers[$server_key][$full_key] = $full_key;
}
if (empty($servers)) {
return array();
}
$try_again_full_keys = array();
foreach ($servers as $server_key => $full_keys) {
// Use the first key of the list as all keys map to this server.
$full_key = current($full_keys);
// Check if lifetime token exists and hence if we are authorized
// on this server.
$rc = $mc
->getByKey($full_key, DRUPAL_MEMCACHE_ASCII_AUTH_LIFETIME_KEY);
if (empty($rc) && _dmemcache_ensure_ascii_auth($full_key, $mc)) {
// If we logged in after first failing a fetch for our lifetime key,
// then these keys need to be retried as the "not found" could have been
// an authentication failure.
$try_again_full_keys += $full_keys;
}
}
// In case no authentication succeeded, there will be no keys to get.
if (empty($try_again_full_keys)) {
return array();
}
$new_results = $mc
->getMulti($try_again_full_keys);
if (empty($new_results)) {
return array();
}
return $new_results;
}