You are here

trait RequestTimeTrait in Supercache 2.0.x

Same name and namespace in other branches
  1. 8 src/Cache/RequestTimeTrait.php \Drupal\supercache\Cache\RequestTimeTrait

Hierarchy

File

src/Cache/RequestTimeTrait.php, line 5

Namespace

Drupal\supercache\Cache
View source
trait RequestTimeTrait {

  /**
   * Current time used to validate
   * cache item expiration times.
   *
   * @var mixed
   */
  protected $requestTime;

  /**
   * Refreshes the current request time.
   *
   * Uses the global REQUEST_TIME on the first
   * call and refreshes to current time on subsequen
   * requests.
   *
   * @param int $time
   */
  public function refreshRequestTime() {
    if (empty($this->requestTime)) {
      if (defined('REQUEST_TIME')) {
        $this->requestTime = REQUEST_TIME;
        return;
      }
      if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
        $this->requestTime = round($_SERVER['REQUEST_TIME_FLOAT'], 3);
        return;
      }
    }
    $this->requestTime = round(microtime(TRUE), 3);
  }

  /**
   * Returns a 12 character length MD5.
   *
   * @param string $string
   * @return string
   */
  protected function shortMd5($string) {
    return substr(base_convert(md5($string), 16, 32), 0, 12);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequestTimeTrait::$requestTime protected property Current time used to validate cache item expiration times.
RequestTimeTrait::refreshRequestTime public function Refreshes the current request time. 1
RequestTimeTrait::shortMd5 protected function Returns a 12 character length MD5.