class Redis_CacheCompressed in Redis 7.3
This typically brings 80..85% compression in ~20ms/mb write, 5ms/mb read.
Hierarchy
- class \Redis_Cache implements DrupalCacheInterface
- class \Redis_CacheCompressed implements DrupalCacheInterface
Expanded class hierarchy of Redis_CacheCompressed
File
- lib/
Redis/ CacheCompressed.php, line 6
View source
class Redis_CacheCompressed extends Redis_Cache implements DrupalCacheInterface {
private $compressionSizeThreshold = 100;
private $compressionRatio = 1;
/**
* {@inheritdoc}
*/
public function __construct($bin) {
parent::__construct($bin);
$this->compressionSizeThreshold = (int) variable_get('cache_compression_size_threshold', 100);
if ($this->compressionSizeThreshold < 0) {
trigger_error('cache_compression_size_threshold must be 0 or a positive integer, negative value found, switching back to default 100', E_USER_WARNING);
$this->compressionSizeThreshold = 100;
}
// Minimum compression level (1) has good ratio in low time.
$this->compressionRatio = (int) variable_get('cache_compression_ratio', 1);
if ($this->compressionRatio < 1 || 9 < $this->compressionRatio) {
trigger_error('cache_compression_ratio must be between 1 and 9, out of bounds value found, switching back to default 1', E_USER_WARNING);
$this->compressionRatio = 1;
}
}
/**
* {@inheritdoc}
*/
protected function createEntryHash($cid, $data, $expire = CACHE_PERMANENT) {
$hash = parent::createEntryHash($cid, $data, $expire);
// Empiric level when compression makes sense.
if (!$this->compressionSizeThreshold || strlen($hash['data']) > $this->compressionSizeThreshold) {
$hash['data'] = gzcompress($hash['data'], $this->compressionRatio);
$hash['compressed'] = true;
}
return $hash;
}
/**
* {@inheritdoc}
*/
protected function expandEntry(array $values, $flushPerm, $flushVolatile) {
if (!empty($values['data']) && !empty($values['compressed'])) {
// Uncompress, suppress warnings e.g. for broken CRC32.
$values['data'] = @gzuncompress($values['data']);
// In such cases, void the cache entry.
if ($values['data'] === false) {
return false;
}
}
return parent::expandEntry($values, $flushPerm, $flushVolatile);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Redis_Cache:: |
protected | property | When in shard mode, the proxy may or may not support pipelining, Twemproxy is known to support it. | |
Redis_Cache:: |
protected | property | When the global 'cache_lifetime' Drupal variable is set to a value, the cache backends should not expire temporary entries by themselves per Drupal signature. Volatile items will be dropped accordingly to their set lifetime. | |
Redis_Cache:: |
protected | property | ||
Redis_Cache:: |
protected | property | ||
Redis_Cache:: |
protected | property | Flush permanent and volatile cached values | |
Redis_Cache:: |
protected | property | When in shard mode, the backend cannot proceed to multiple keys operations, and won't delete keys on flush calls. | |
Redis_Cache:: |
protected | property | Maximum TTL for this bin from Drupal configuration. | |
Redis_Cache:: |
protected | property | Default TTL for CACHE_PERMANENT items. | |
Redis_Cache:: |
public | function | Does this bin allow pipelining through sharded environment | |
Redis_Cache:: |
public | function | Does this bin allow temporary item flush | |
Redis_Cache:: |
public | function |
Expires data from the cache. Overrides DrupalCacheInterface:: |
|
Redis_Cache:: |
constant | Uses EVAL scripts to flush data when called | ||
Redis_Cache:: |
constant | This mode is tailored for sharded Redis servers instances usage: it will never delete entries but only mark the latest flush timestamp into one of the servers in the shard. It will proceed to delete on read single entries when invalid entries are… | ||
Redis_Cache:: |
constant | Same as the one above, plus attempt to do pipelining when possible. | ||
Redis_Cache:: |
public | function |
Returns data from the persistent cache. Overrides DrupalCacheInterface:: |
|
Redis_Cache:: |
public | function | Get latest flush time | |
Redis_Cache:: |
public | function | Get maximum TTL for all items. | |
Redis_Cache:: |
public | function |
Returns data from the persistent cache when given an array of cache IDs. Overrides DrupalCacheInterface:: |
|
Redis_Cache:: |
public | function | From the given timestamp build an incremental safe time-based identifier. | |
Redis_Cache:: |
public | function | Get TTL for CACHE_PERMANENT items. | |
Redis_Cache:: |
public | function | Get valid checksum | |
Redis_Cache:: |
public | function |
Checks if a cache bin is empty. Overrides DrupalCacheInterface:: |
|
Redis_Cache:: |
public | function | Is this bin in shard mode | |
Redis_Cache:: |
constant | Computed keys are let's say arround 60 characters length due to key prefixing, which makes 1,000 keys DEL command to be something arround 50,000 bytes length: this is huge and may not pass into Redis, let's split this off. Some recommend to… | ||
Redis_Cache:: |
constant | Default lifetime for permanent items. Approximatively 1 year. | ||
Redis_Cache:: |
public | function | Find from Drupal variables the clear mode. | |
Redis_Cache:: |
public | function | Find from Drupal variables the maximum cache lifetime. | |
Redis_Cache:: |
protected | function | Find from Drupal variables the right permanent items TTL. | |
Redis_Cache:: |
public | function |
Stores data in the persistent cache. Overrides DrupalCacheInterface:: |
|
Redis_Cache:: |
public | function | Set last flush time | |
Redis_CacheCompressed:: |
private | property | ||
Redis_CacheCompressed:: |
private | property | ||
Redis_CacheCompressed:: |
protected | function |
Create cache entry Overrides Redis_Cache:: |
|
Redis_CacheCompressed:: |
protected | function |
Expand cache entry from fetched data Overrides Redis_Cache:: |
|
Redis_CacheCompressed:: |
public | function |
Overrides Redis_Cache:: |