Example #1
0
 /**
  * Sets the number of seconds before a page cached on a browser expires.
  *
  * @throws Phoenix\Exceptions\FailureException if HTTP headers have been sent
  * @param string|int|\DateTime $time
  *            [optional] default null means no cache, otherwise it is cache time; supported format here http://php.net/manual/en/datetime.formats.php
  * @return void
  */
 public final function setExpiration($time = null)
 {
     if (empty($time)) {
         // no cache
         $this->setHeader("Cache-Control", "s-maxage=0, max-age=0, must-revalidate");
         $this->setHeader("Expires", "Tue, 1 Jan 1991 00:00:00 GMT");
         return;
     }
     $time = DateTime::from($time);
     $this->setHeader("Cache-Control", "max-age=" . ($time->format("U") - time()));
     $this->setHeader("Expires", DateTime::formatHttpDate($time));
     return;
 }