本文整理汇总了PHP中Cake\Cache\Cache::enabled方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::enabled方法的具体用法?PHP Cache::enabled怎么用?PHP Cache::enabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Cache\Cache
的用法示例。
在下文中一共展示了Cache::enabled方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeLayout
/**
* Callback for Helper::beforeLayout
*
* @param Event $view Event
* @param string $layoutFile layout file name
*
* @return bool true
*/
public function beforeLayout(Event $event, $layoutFile)
{
if (!Cache::enabled()) {
$this->config('disable', true);
} elseif (!$this->request->is('get')) {
$this->config('disable', true);
} elseif ($this->request->session()->check('Flash')) {
$this->config('disable', true);
} elseif ($this->_View->get(ViewMemcachedHelper::NOCACHE)) {
$this->config('disable', true);
}
if ($this->_View->get(ViewMemcachedHelper::DELETE) === true) {
Cache::delete($this->config('cacheKey'), $this->config('cacheConfig'));
}
return true;
}
示例2: cache
/**
* Reads/writes temporary data to cache files or session.
*
* @param string $path File path within /tmp to save the file.
* @param mixed $data The data to save to the temporary file.
* @param mixed $expires A valid strtotime string when the data expires.
* @param string $target The target of the cached data; either 'cache' or 'public'.
* @return mixed The contents of the temporary file.
* @deprecated Will be removed in 3.0. Please use Cache::write() instead.
*/
function cache($path, $data = null, $expires = '+1 day', $target = 'cache')
{
if (!Cache::enabled()) {
return null;
}
$now = time();
if (!is_numeric($expires)) {
$expires = strtotime($expires, $now);
}
switch (strtolower($target)) {
case 'cache':
$filename = CACHE . $path;
break;
case 'public':
$filename = WWW_ROOT . $path;
break;
case 'tmp':
$filename = TMP . $path;
break;
}
$timediff = $expires - $now;
$filetime = false;
if (file_exists($filename)) {
//@codingStandardsIgnoreStart
$filetime = @filemtime($filename);
//@codingStandardsIgnoreEnd
}
if ($data === null) {
if (file_exists($filename) && $filetime !== false) {
if ($filetime + $timediff < $now) {
//@codingStandardsIgnoreStart
@unlink($filename);
//@codingStandardsIgnoreEnd
} else {
//@codingStandardsIgnoreStart
$data = @file_get_contents($filename);
//@codingStandardsIgnoreEnd
}
}
} elseif (is_writable(dirname($filename))) {
//@codingStandardsIgnoreStart
@file_put_contents($filename, $data, LOCK_EX);
//@codingStandardsIgnoreEnd
}
return $data;
}
示例3: testEnableDisableEnabled
/**
* Test toggling enabled state of cache.
*
* @return void
*/
public function testEnableDisableEnabled()
{
$this->assertNull(Cache::enable());
$this->assertTrue(Cache::enabled(), 'Should be on');
$this->assertNull(Cache::disable());
$this->assertFalse(Cache::enabled(), 'Should be off');
}
示例4: tmpViewer
/**
* Temporary files viewer (assets, cache, logs, sitemap and thumbnails)
* @return void
*/
public function tmpViewer()
{
$assetsSize = (new Folder(Configure::read('Assets.target')))->dirsize();
$cacheSize = (new Folder(CACHE))->dirsize();
$logsSize = (new Folder(LOGS))->dirsize();
$sitemapSize = is_readable(SITEMAP) ? filesize(SITEMAP) : 0;
$thumbsSize = (new Folder(Configure::read('Thumbs.target')))->dirsize();
$this->set(am(['cacheStatus' => Cache::enabled(), 'totalSize' => $assetsSize + $cacheSize + $logsSize + $sitemapSize + $thumbsSize], compact('assetsSize', 'cacheSize', 'logsSize', 'sitemapSize', 'thumbsSize')));
}