public static function MemcacheStorageAPI::add in Memcache Storage 7
Save data into memcached pool if key doesn't exist. Provide debug logging.
See also
http://www.php.net/manual/en/memcache.set.php
1 call to MemcacheStorageAPI::add()
- lock_acquire in includes/
lock.inc - Acquire (or renew) a lock, but do not block if it fails.
File
- ./
memcache_storage.api.inc, line 300 - Provide class that processes memcached operations.
Class
- MemcacheStorageAPI
- Integrates with memcache API.
Code
public static function add($cache_id, $data, $expire, $cache_bin = '') {
// Get memcache object.
$memcache = self::openConnection($cache_bin);
// No memcache connection.
if (empty($memcache)) {
return FALSE;
}
// Build unique cache id.
$cid = self::preprocessCacheKey($cache_id, $cache_bin);
// Run initial debug actions.
if (variable_get('memcache_storage_debug', FALSE)) {
self::initialDebugActions();
}
// Set data to memcached pool.
$result = FALSE;
if ($memcache instanceof Memcache) {
// Get compression mode.
$compressed = variable_get('memcache_storage_compress_data') ? MEMCACHE_COMPRESSED : 0;
$result = @$memcache
->add($cid, $data, $compressed, $expire);
}
elseif ($memcache instanceof Memcached) {
@$memcache
->add($cid, $data, $expire);
$result = $memcache
->getResultCode() != Memcached::RES_SUCCESS ? FALSE : TRUE;
}
// Run final debug actions.
if (variable_get('memcache_storage_debug', FALSE)) {
self::finalDebugActions('add', $cache_bin, $cache_id, $cid, $result);
}
return $result;
}