コード例 #1
0
ファイル: ProxyBase.php プロジェクト: emma5021/toba
 /**
  * Sets the caching (Cache-Control & Expires) with a cache age of $lastModified
  * or if $lastModified === false, sets Pragma: no-cache & Cache-Control: no-cache
  */
 protected function setCachingHeaders($lastModified = false)
 {
     $maxAge = $this->context->getIgnoreCache() ? false : $this->context->getRefreshInterval();
     if ($maxAge) {
         if ($lastModified) {
             header("Last-Modified: {$lastModified}");
         }
         // time() is a kernel call, so lets avoid it and use the request time instead
         $time = $_SERVER['REQUEST_TIME'];
         $expires = $maxAge !== false ? $time + $maxAge : $time - 3000;
         $public = $maxAge ? 'public' : 'private';
         $maxAge = $maxAge === false ? '0' : $maxAge;
         header("Cache-Control: {$public}; max-age={$maxAge}", true);
         header("Expires: " . gmdate("D, d M Y H:i:s", $expires) . " GMT", true);
     } else {
         header("Cache-Control: no-cache", true);
         header("Pragma: no-cache", true);
     }
 }