Example #1
0
 function isCached($key, $duration = 60, array $params = array())
 {
     $suffix = strstr($key, 'sql') ? '_SQL' : '';
     $cache = new Cache(CACHE_PATH . DS);
     $hash = sha1($key . $duration . _serialize($params)) . $suffix . '.cache';
     return $cache->has($hash);
 }
Example #2
0
 protected function _run()
 {
     $viewRedis = container()->getViewRedis();
     $echo = func_get_arg(0);
     $file = $this->_viewFile;
     $isExpired = $this->expired();
     if (false === $this->_compiled) {
         $isExpired = true;
     }
     if (false === $isExpired) {
         $file = $this->compiled();
     } else {
         if (is_numeric($this->_cache)) {
             $cacheInst = new Cache(CACHE_PATH . DS);
             $hash = sha1($this->compiled() . $this->_cache . _serialize((array) $this)) . '.cache';
             $cacheInst->forget($hash);
         }
         $file = $this->compiled($file);
     }
     if (null !== $this->_cache) {
         $isCached = isCached($file, $this->_cache, (array) $this);
         if (false === $isCached) {
             ob_start();
             if (true !== $viewRedis) {
                 include $file;
             }
             $content = ob_get_contents();
             ob_end_clean();
             if (true === $echo) {
                 if (true !== $viewRedis) {
                     echo cache($file, $content, $this->_cache, (array) $this);
                 }
             } else {
                 if (true !== $viewRedis) {
                     return cache($file, $content, $this->_cache, (array) $this);
                 }
             }
         } else {
             if (true !== $viewRedis) {
                 $content = cache($file, null, $this->_cache, (array) $this);
                 if (true === $echo) {
                     echo $content;
                 } else {
                     return $content;
                 }
             }
         }
     } else {
         if (true === $echo) {
             if (true !== $viewRedis) {
                 include $file;
             } else {
                 $this->compile($file);
             }
         } else {
             ob_start();
             if (true !== $viewRedis) {
                 include $file;
             } else {
                 $this->compile($file);
             }
             $content = ob_get_contents();
             ob_end_clean();
             $hash = sha1($this->_viewFile);
             Utils::set($hash, $content);
             return $content;
         }
     }
 }