当前位置: 首页>>代码示例>>PHP>>正文


PHP CakeResponse::cache方法代码示例

本文整理汇总了PHP中CakeResponse::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeResponse::cache方法的具体用法?PHP CakeResponse::cache怎么用?PHP CakeResponse::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CakeResponse的用法示例。


在下文中一共展示了CakeResponse::cache方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _deliver

 protected function _deliver(CakeResponse $response, Asset $asset)
 {
     ob_start();
     $compressionEnabled = Configure::read('Asset.compress') && $response->compress();
     if ($response->type($asset->extension()) == $asset->extension()) {
         $contentType = 'application/octet-stream';
         $agent = env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $response->type($contentType);
     }
     if (!$compressionEnabled) {
         $response->header('Content-Length', $asset->size());
     }
     $response->cache(filemtime($asset->file));
     $response->send();
     ob_clean();
     echo $asset->content();
     if ($compressionEnabled) {
         ob_end_flush();
     }
 }
开发者ID:rodrigorm,项目名称:asset-plugin,代码行数:23,代码来源:AssetsDispatcher.php

示例2: _deliverAsset

 /**
  * Sends an asset file to the client
  *
  * @param string $assetFile Path to the asset file in the file system
  * @param string $ext The extension of the file to determine its mime type
  * @return void
  */
 protected function _deliverAsset($assetFile, $ext)
 {
     ob_start();
     $compressionEnabled = Configure::read('Asset.compress') && $this->response->compress();
     if ($this->response->type($ext) == $ext) {
         $contentType = 'application/octet-stream';
         $agent = env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $this->response->type($contentType);
     }
     $this->response->cache(filemtime($assetFile));
     $this->response->send();
     ob_clean();
     if ($ext === 'css' || $ext === 'js') {
         include $assetFile;
     } else {
         readfile($assetFile);
     }
     if ($compressionEnabled) {
         ob_end_flush();
     }
 }
开发者ID:robotarmy,项目名称:Phog,代码行数:31,代码来源:dispatcher.php

示例3: testCache

 /**
  * Tests the cache method
  *
  */
 public function testCache()
 {
     $response = new CakeResponse();
     $since = time();
     $time = new DateTime('+1 day', new DateTimeZone('UTC'));
     $response->expires('+1 day');
     $expected = array('Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT', 'Last-Modified' => gmdate("D, j M Y H:i:s ", $since) . 'GMT', 'Expires' => $time->format('D, j M Y H:i:s') . ' GMT', 'Cache-Control' => 'public, max-age=' . ($time->format('U') - time()));
     $response->cache($since);
     $this->assertEquals($expected, $response->header());
     $response = new CakeResponse();
     $since = time();
     $time = '+5 day';
     $expected = array('Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT', 'Last-Modified' => gmdate("D, j M Y H:i:s ", $since) . 'GMT', 'Expires' => gmdate("D, j M Y H:i:s", strtotime($time)) . " GMT", 'Cache-Control' => 'public, max-age=' . (strtotime($time) - time()));
     $response->cache($since, $time);
     $this->assertEquals($expected, $response->header());
     $response = new CakeResponse();
     $since = time();
     $time = time();
     $expected = array('Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT', 'Last-Modified' => gmdate("D, j M Y H:i:s ", $since) . 'GMT', 'Expires' => gmdate("D, j M Y H:i:s", $time) . " GMT", 'Cache-Control' => 'public, max-age=0');
     $response->cache($since, $time);
     $this->assertEquals($expected, $response->header());
 }
开发者ID:pushpendraraj,项目名称:tigzie,代码行数:26,代码来源:CakeResponseTest.php

示例4: testCache

/**
* Tests the cache method
*
*/
	public function testCache() {
		$response = new CakeResponse();
		$since = time();
		$time = '+1 day';
		$expected = array(
			'Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
			'Last-Modified' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
			'Expires' => gmdate("D, j M Y H:i:s", strtotime($time)) . " GMT",
			'Cache-Control' => 'public, max-age=' . (strtotime($time) - time()),
			'Pragma' => 'cache'
		);
		$response->cache($since);
		$this->assertEquals($response->header(), $expected);

		$response = new CakeResponse();
		$since = time();
		$time = '+5 day';
		$expected = array(
			'Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
			'Last-Modified' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
			'Expires' => gmdate("D, j M Y H:i:s", strtotime($time)) . " GMT",
			'Cache-Control' => 'public, max-age=' . (strtotime($time) - time()),
			'Pragma' => 'cache'
		);
		$response->cache($since, $time);
		$this->assertEquals($response->header(), $expected);

		$response = new CakeResponse();
		$since = time();
		$time = time();
		$expected = array(
			'Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
			'Last-Modified' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
			'Expires' => gmdate("D, j M Y H:i:s", $time) . " GMT",
			'Cache-Control' => 'public, max-age=0',
			'Pragma' => 'cache'
		);
		$response->cache($since, $time);
		$this->assertEquals($response->header(), $expected);
	}
开发者ID:sherix88,项目名称:sigedu,代码行数:44,代码来源:CakeResponseTest.php

示例5: render

 /**
  * Display or download the given file
  *
  * @param string $view Not used
  * @param string $layout Not used
  * @return mixed
  * @throws NotFoundException
  */
 public function render($view = null, $layout = null)
 {
     $name = $download = $extension = $id = $modified = $path = $cache = $mimeType = $compress = null;
     extract($this->viewVars, EXTR_OVERWRITE);
     if (is_dir($path)) {
         $path = $path . $id;
     } else {
         $path = APP . $path . $id;
     }
     if (!is_file($path)) {
         if (Configure::read('debug')) {
             throw new NotFoundException(sprintf('The requested file %s was not found', $path));
         }
         throw new NotFoundException('The requested file was not found');
     }
     if (is_array($mimeType)) {
         $this->response->type($mimeType);
     }
     if (isset($extension) && $this->_isActive()) {
         $extension = strtolower($extension);
         $chunkSize = 8192;
         $buffer = '';
         $fileSize = @filesize($path);
         $handle = fopen($path, 'rb');
         if ($handle === false) {
             return false;
         }
         if (!empty($modified) && !is_numeric($modified)) {
             $modified = strtotime($modified, time());
         } else {
             $modified = time();
         }
         if ($this->response->type($extension) === false) {
             $download = true;
         }
         if ($cache) {
             $this->response->cache($modified, $cache);
         } else {
             $this->response->header(array('Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT', 'Expires' => '0', 'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'no-cache'));
         }
         if ($download) {
             $agent = env('HTTP_USER_AGENT');
             if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
                 $contentType = 'application/octetstream';
             } else {
                 if (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
                     $contentType = 'application/force-download';
                 }
             }
             if (!empty($contentType)) {
                 $this->response->type($contentType);
             }
             if (is_null($name)) {
                 $name = $id;
             }
             $this->response->download($name);
             $this->response->header(array('Accept-Ranges' => 'bytes'));
             $httpRange = env('HTTP_RANGE');
             if (isset($httpRange)) {
                 list($toss, $range) = explode('=', $httpRange);
                 $size = $fileSize - 1;
                 $length = $fileSize - $range;
                 $this->response->header(array('Content-Length' => $length, 'Content-Range' => 'bytes ' . $range . $size . '/' . $fileSize));
                 $this->response->statusCode(206);
                 fseek($handle, $range);
             } else {
                 $this->response->header('Content-Length', $fileSize);
             }
         } else {
             $this->response->header(array('Content-Length' => $fileSize));
         }
         $this->_clearBuffer();
         if ($compress) {
             $this->_compressionEnabled = $this->response->compress();
         }
         $this->response->send();
         return $this->_sendFile($handle);
     }
     return false;
 }
开发者ID:Chromedian,项目名称:inventory,代码行数:88,代码来源:MediaView.php


注:本文中的CakeResponse::cache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。