Example #1
0
 function deleteCache($cid)
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
     $cmData = new CacheData($client->path . DS . 'cache');
     $cmData->cleanCacheList($cid);
 }
Example #2
0
 /**
  * Clear Joomla Cache By groups, just apply for the front-page.
  *
  * @param array $group
  */
 function clearCacheByGroups($params, $groups)
 {
     // include cache model from the cache component
     $file = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_cache' . DS . 'cache.class.php';
     if (file_exists($file)) {
         $client =& JApplicationHelper::getClientInfo(0);
         $cmData = new CacheData($client->path . DS . 'cache');
         return $cmData->cleanCacheList($groups);
     }
 }
Example #3
0
 protected function afterAction($action)
 {
     parent::afterAction($action);
     //        echo 'after';
     if ($this->_conf['cache_page_status'] == 'open') {
         $cacheTime = $this->_conf['cache_page_time'];
         $cacheId = $this->_thisUrl;
         ob_start();
         $pageData = ob_get_contents();
         if (Yii::app()->cache->set($cacheId, $pageData, $cacheTime)) {
             //记录
             echo '写入cache';
             CacheData::_addMycache('页面缓存', $cacheId, $cacheTime, $this->_thisUrl);
         }
     }
 }
Example #4
0
 public static function getData($board, $period, $time)
 {
     if (0 == $period) {
         // year: format: YYYY, 一天一筆最高的
         $max_time = mktime(0, 0, 0, 1, 1, $time + 1);
         $min_time = mktime(0, 0, 0, 1, 1, $time);
     } elseif (1 == $period) {
         // month: format: YYYYMM, 一天12筆
         list($year, $month) = sscanf($time, "%4d%2d");
         $min_time = mktime(0, 0, 0, $month, 1, $year);
         $max_time = strtotime('+1 month', $min_time);
     } elseif (3 == $period) {
         // daily: format: YYYYMMDD, 全部
         list($year, $month, $day) = sscanf($time, "%4d%2d%2d");
         $min_time = mktime(1, 1, 1, $month, $day, $year);
         $max_time = $min_time + 86400;
     }
     $last_update = RankData::search(array('board' => $board))->search("`time` < {$max_time}")->order("`time` DESC")->first()->time;
     if (!$last_update) {
         return array();
     }
     if ($data = CacheData::search(array("board" => $board, "period" => $period, "time" => $time, "updated_at" => $last_update))->first()) {
         return json_decode($data->data);
     }
     if (0 == $period) {
         $datas = array();
         for ($t = $min_time; $t < $max_time; $t += 86400) {
             $max_data = RankData::search(array('board' => $board))->search("`time` >= {$t} and `time` < {$t} + 86400")->max('count');
             if (!$max_data) {
                 continue;
             }
             $datas[] = array($max_data->time, $max_data->count);
         }
     }
     try {
         CacheData::insert(array('board' => $board, 'period' => $period, 'time' => $time, 'updated_at' => $last_update, 'data' => json_encode($datas, JSON_UNESCAPED_UNICODE)));
     } catch (Pix_Table_DuplicateException $e) {
         CacheData::search(array('board' => $board, 'period' => $period, 'time' => $time))->update(array('updated_at' => $last_update, 'data' => json_encode($datas, JSON_UNESCAPED_UNICODE)));
     }
     return $datas;
 }
Example #5
0
 public function appendRecursionData(CacheData $d)
 {
     if (!$d->getKey()) {
         throw new Exceptions\CacheInvalidDataException();
     }
     $this->addDependency($d->getKey());
     $this->data[] = array('type' => self::CACHEDATA_TYPE_RECURSION_DATA, 'data' => $d->getKey());
     return $this;
 }
Example #6
0
 /**
  *
  * @param CacheKey $k
  * @param integer $lifetime if null uses the class default
  * @param boolean $print
  * @param boolean $fail if true throws a NotCachedException if not cached.
  * @throws Cachearium\Exceptions\NotCachedException
  * @throws Cachearium\Exceptions\CacheKeyClashException
  * @return string The cached item as a string or false if not cached.
  */
 public function recursiveStart(CacheKey $k, $lifetime = null, $print = true, $fail = false)
 {
     // @codeCoverageIgnoreStart
     if (!$this->enabled) {
         return false;
     }
     // @codeCoverageIgnoreEnd
     foreach ($this->loopdata as $l) {
         /* @var $l CacheData */
         if ($l->checkClash($k)) {
             throw new Exceptions\CacheKeyClashException();
         }
     }
     // check if we are inside another cache for automatic dependencies.
     /* @var $cachedata CacheData */
     $cachedata = null;
     try {
         $cachedata = $this->getData($k);
         if (!$cachedata->checkUpdateToDate($this)) {
             // stale
             $cachedata = null;
         }
         // TODO $this->prefetch($cachedata->getDependencies());
     } catch (Exceptions\NotCachedException $e) {
     }
     // found. just return it.
     if ($cachedata) {
         try {
             $this->log(CacheLogEnum::ACCESSED, $cachedata->key, $cachedata->lifetime);
             $key = "cache-" . rand();
             $retval = $cachedata->stringify($this);
             if ($print) {
                 // @codeCoverageIgnoreStart
                 if (static::$debugOnPage) {
                     $this->printProbeStart($key, $cachedata, 'hit');
                 }
                 // @codeCoverageIgnoreEnd
                 echo $retval;
                 // @codeCoverageIgnoreStart
                 if (static::$debugOnPage) {
                     $this->printProbeEnd($key, $cachedata);
                 }
                 // @codeCoverageIgnoreEnd
             }
             return $retval;
         } catch (Exceptions\NotCachedException $e) {
             $this->delete($k);
             // clear recursively
             if ($this->inloop) {
                 throw $e;
             }
         }
     }
     if ($fail) {
         throw new Exceptions\NotCachedException();
     }
     $this->inloop++;
     $cd = new CacheData($k);
     $cd->setLifetime($lifetime ? $lifetime : $this->lifetime);
     $this->loopdata[$this->inloop] = $cd;
     if ($this->inloop > 1) {
         // we are recursive. push whatever we have so far in the previous cache
         $data = ob_get_contents();
         ob_clean();
         foreach ($this->loopdata as $l) {
             if ($l == $cd) {
                 // don't depend on itself
                 continue;
             }
             /* @var $l CacheData */
             $l->addDependency($k);
         }
         $this->loopdata[$this->inloop - 1]->appendData($data);
         $this->loopdata[$this->inloop - 1]->appendRecursionData($cd);
     } else {
         // something was not cached below. We invalidated all cache
         // dependencies
     }
     ob_start();
     ob_implicit_flush(false);
     return false;
 }