You are here

public function CacheBase::setPermTtl in Redis 8

Set the permanent TTL.

1 call to CacheBase::setPermTtl()
CacheBase::__construct in src/Cache/CacheBase.php
CacheBase constructor.

File

src/Cache/CacheBase.php, line 256

Class

CacheBase
Base class for redis cache backends.

Namespace

Drupal\redis\Cache

Code

public function setPermTtl($ttl = NULL) {
  if (isset($ttl)) {
    $this->permTtl = $ttl;
  }
  else {

    // Attempt to set from settings.
    if (($settings = Settings::get('redis.settings', [])) && isset($settings['perm_ttl_' . $this->bin])) {
      $ttl = $settings['perm_ttl_' . $this->bin];
      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 {

          // Log error about invalid ttl.
          trigger_error(sprintf("Parsed TTL '%s' has an invalid value: switching to default", $ttl));
          $this->permTtl = self::LIFETIME_PERM_DEFAULT;
        }
      }
    }
  }
}