コード例 #1
0
 /**
  * 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
0
ファイル: basics.php プロジェクト: ripzappa0924/carte0.0.1
 /**
  * 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
0
ファイル: CacheTest.php プロジェクト: maitrepylos/nazeweb
 /**
  * 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
0
 /**
  * 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')));
 }