You are here

public function Redis_Cache_Base::__construct in Redis 7.2

Default constructor

Overrides Redis_AbstractBackend::__construct

File

lib/Redis/Cache/Base.php, line 156

Class

Redis_Cache_Base
Because those objects will be spawned during boostrap all its configuration must be set in the settings.php file.

Code

public function __construct($bin) {
  parent::__construct($bin);
  $this->bin = $bin;

  // Check if the server can use EVAL
  if (variable_get('redis_eval_enabled', false)) {
    $this->useEval = true;
  }
  if (null !== ($mode = variable_get('redis_flush_mode_' . $this->bin, null))) {

    // A bin specific flush mode has been set.
    $this->clearMode = (int) $mode;
  }
  else {
    if (null !== ($mode = variable_get('redis_flush_mode', null))) {

      // A site wide generic flush mode has been set.
      $this->clearMode = (int) $mode;
    }
    else {

      // No flush mode is set by configuration: provide sensible defaults.
      // See FLUSH_* constants for comprehensible explaination of why this
      // exists.
      switch ($this->bin) {
        case 'cache_page':
        case 'cache_block':
          $this->clearMode = self::FLUSH_TEMPORARY;
          break;
        default:
          $this->clearMode = self::FLUSH_NOTHING;
          break;
      }
    }
  }
  $ttl = null;
  if (null === ($ttl = variable_get('redis_perm_ttl_' . $this->bin, null))) {
    if (null === ($ttl = variable_get('redis_perm_ttl', null))) {
      $ttl = self::LIFETIME_PERM_DEFAULT;
    }
  }
  if ($ttl === (int) $ttl) {
    $this->permTtl = $ttl;
  }
  else {
    if ($iv = DateInterval::createFromDateString($ttl)) {

      // http://stackoverflow.com/questions/14277611/convert-dateinterval-object-to-seconds-in-php
      $this->permTtl = $iv->y * 31536000 + $iv->m * 2592000 + $iv->days * 86400 + $iv->h * 3600 + $iv->i * 60 + $iv->s;
    }
    else {

      // Sorry but we have to log this somehow.
      trigger_error(sprintf("Parsed TTL '%s' has an invalid value: switching to default", $ttl));
      $this->permTtl = self::LIFETIME_PERM_DEFAULT;
    }
  }
}