abstract class DrupalMemcacheBase in Zircon Profile 8
Same name and namespace in other branches
- 8.0 modules/memcache/src/DrupalMemcacheBase.php \Drupal\memcache\DrupalMemcacheBase
Class DrupalMemcacheBase.
Hierarchy
- class \Drupal\memcache\DrupalMemcacheBase implements DrupalMemcacheInterface
Expanded class hierarchy of DrupalMemcacheBase
File
- modules/
memcache/ src/ DrupalMemcacheBase.php, line 16 - Contains \Drupal\memcache\DrupalMemcacheBase.
Namespace
Drupal\memcacheView source
abstract class DrupalMemcacheBase implements DrupalMemcacheInterface {
/**
* The cache bin name.
*
* @var string
*/
protected $bin;
/**
* The settings object.
*
* @var \Drupal\Core\Site\Settings
*/
protected $settings;
/**
* The memcache object.
*
* @var mixed
* E.g. \Memcache|\Memcached
*/
protected $memcache;
/**
* The hash algorithm to pass to hash(). Defaults to 'sha1'
*
* @var string
*/
protected $hashAlgorithm;
/**
* Constructs a DrupalMemcacheBase object.
*
* @param string $bin
* The cache bin.
* @param \Drupal\Core\Site\Settings
* The settings object.
*/
public function __construct($bin, Settings $settings) {
$this->bin = $bin;
$this->settings = $settings;
$this->hashAlgorithm = $this->settings
->get('memcache_key_hash_algorithm', 'sha1');
}
/**
* {@inheritdoc}
*/
public function get($key) {
$full_key = $this
->key($key);
$track_errors = ini_set('track_errors', '1');
$php_errormsg = '';
$result = @$this->memcache
->get($full_key);
if (!empty($php_errormsg)) {
register_shutdown_function('memcache_log_warning', LogLevel::WARNING, 'Exception caught in DrupalMemcacheBase::get: !msg', array(
'!msg' => $php_errormsg,
));
$php_errormsg = '';
}
ini_set('track_errors', $track_errors);
return $result;
}
/**
* {@inheritdoc}
*/
public function key($key) {
$full_key = urlencode($this->bin . '-' . $key);
// Memcache only supports key lengths up to 250 bytes. If we have generated
// a longer key, we shrink it to an acceptable length with a configurable
// hashing algorithm. Sha1 was selected as the default as it performs
// quickly with minimal collisions.
if (strlen($full_key) > 250) {
$full_key = urlencode(hash($this->hashAlgorithm, $this->bin . '-' . $key));
}
return $full_key;
}
/**
* {@inheritdoc}
*/
public function delete($key) {
$full_key = $this
->key($key);
return $this->memcache
->delete($full_key, 0);
}
/**
* {@inheritdoc}
*/
public function flush() {
$this->memcache
->flush();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalMemcacheBase:: |
protected | property | The cache bin name. | |
DrupalMemcacheBase:: |
protected | property | The hash algorithm to pass to hash(). Defaults to 'sha1' | |
DrupalMemcacheBase:: |
protected | property | The memcache object. | |
DrupalMemcacheBase:: |
protected | property | The settings object. | |
DrupalMemcacheBase:: |
public | function |
Deletes an item from Memcache. Overrides DrupalMemcacheInterface:: |
|
DrupalMemcacheBase:: |
public | function |
Immediately invalidates all existing items. Overrides DrupalMemcacheInterface:: |
|
DrupalMemcacheBase:: |
public | function |
Retrieves a value from Memcache. Overrides DrupalMemcacheInterface:: |
|
DrupalMemcacheBase:: |
public | function |
Prepares the memcache key. Overrides DrupalMemcacheInterface:: |
|
DrupalMemcacheBase:: |
public | function | Constructs a DrupalMemcacheBase object. | 2 |
DrupalMemcacheInterface:: |
public | function | Adds a memcache server. | 2 |
DrupalMemcacheInterface:: |
public | function | Retrieves multiple values from Memcache. | 2 |
DrupalMemcacheInterface:: |
public | function | Adds an item into memcache. | 2 |