/** * */ public static function getLanguages() { $languages = CacheHelper::get('languages'); if (!$languages) { $languages = self::find()->orderBy(['position' => SORT_ASC])->all(); CacheHelper::set('languages', $languages, CacheHelper::getTag(self::className())); } return $languages; }
public static function getActiveVotes() { $cacheKey = "activeVotes"; $allVotes = CacheHelper::get($cacheKey); if (false === $allVotes) { $allVotes = Vote::find()->active()->language()->order()->all(); CacheHelper::set($cacheKey, $allVotes, CacheHelper::getTag(Vote::className())); } return $allVotes; }
public static function processRedirect() { $redirects = CacheHelper::get('redirects'); if (empty($redirects)) { $redirects = (new Query())->select(['old_url', 'new_url'])->from(Redirect::tableName())->all(); $redirects = ArrayHelper::map($redirects, 'old_url', 'new_url'); CacheHelper::set('redirects', $redirects, CacheHelper::getTag(self::className())); } $url = $_SERVER['REQUEST_URI']; if (isset($redirects[$url])) { Yii::$app->response->redirect($redirects[$url], 301); } }
public function run() { $activeVote = $isVoted = false; $allVotes = Vote::getActiveVotes(); if (!empty($allVotes)) { $validVotes = Vote::getValidVotes($allVotes); if (!empty($validVotes)) { $firstVote = reset($validVotes); foreach ($allVotes as $vote) { if ($vote->id == $firstVote) { $activeVote = $vote; } } $isVoted = false; } else { $activeVote = end($allVotes); $isVoted = true; } } if ($activeVote) { $options = []; $voteOptions = CacheHelper::get(Vote::VOTE_OPTIONS_CACHE_KEY . $activeVote->id); if (false === $voteOptions) { $voteOptions = $activeVote->voteOptions; CacheHelper::set(Vote::VOTE_OPTIONS_CACHE_KEY . $activeVote->id, $voteOptions, CacheHelper::getTag(Vote::className())); } $maxPercent = 0; if (!empty($voteOptions)) { if ($isVoted) { $options = $voteOptions; $maxPercent = $activeVote->getMaxPercent(); } else { foreach ($voteOptions as $option) { $options[$option->id] = $option->title; } } } return $this->render('Vote', ['vote' => $activeVote, 'options' => $options, 'isVoted' => $isVoted, 'maxPercent' => $maxPercent]); } else { return ''; } }
static function getBlockFromCache($cacheKey) { return CacheHelper::get($cacheKey); }
public function getStructure() { $owner = $this->owner; $cacheKey = CacheHelper::getTag($owner::className()) . '_items_tree' . Yii::$app->language; $structure = CacheHelper::get($cacheKey); if (!$structure) { $structure = $this->makeStructure(); CacheHelper::set($cacheKey, $structure, CacheHelper::getTag($owner::className())); } return $structure; }