function dmemcache_get in Memcache API and Integration 5
Same name and namespace in other branches
- 5.2 dmemcache.inc \dmemcache_get()
- 6 dmemcache.inc \dmemcache_get()
- 7 dmemcache.inc \dmemcache_get()
Retrieve a value from the cache.
Parameters
$key The key with which the item was stored.:
$bin The bin in which the item was stored.:
Return value
The item which was originally saved or FALSE
5 calls to dmemcache_get()
- cache_get in ./
memcache.db.inc - Return data from the persistent cache.
- cache_get in ./
memcache.inc - Return data from the persistent cache.
- sess_read in ./
memcache-session.inc - sess_regenerate in ./
memcache-session.inc - sess_user_load in ./
memcache-session.inc
File
- ./
dmemcache.inc, line 56
Code
function dmemcache_get($key, $bin = 'cache') {
global $_memcache_statistics;
$_memcache_statistics['get'][] = $key;
$_memcache_statistics['bins'][] = $bin;
if ($mc = dmemcache_object($bin)) {
$full_key = dmemcache_key($key, $bin);
$result = $mc
->get($full_key);
if ($result) {
// We check $result->expire to see if the object has expired. If so, we
// try and grab a lock. If we get the lock, we return FALSE instead of
// the cached object which should cause it to be rebuilt. If we do not
// get the lock, we return the cached object. The goal here is to avoid
// cache stampedes.
// By default the cache stampede semaphore is held for 15 seconds. This
// can be adjusted by setting the memcache_stampede_semaphore variable.
// TODO: Can we log when a sempahore expires versus being intentionally
// freed to track when this is happening?
if (isset($result->expire) && $result->expire <= $_SERVER['REQUEST_TIME'] && $mc
->add($full_key . '_semaphore', '', FALSE, variable_get('memcache_stampede_semaphore', 15))) {
$result = FALSE;
}
else {
$_memcache_statistics['hit'][] = $key;
}
}
return $result;
}
}