public function behaviors() { $sql = (new Query())->select('MAX(update_time)')->from(Post::tableName())->createCommand()->rawSql; return [['class' => 'yii\\filters\\PageCache', 'only' => ['rss', 'atom'], 'duration' => 24 * 60 * 60, 'dependency' => ['class' => DbDependency::className(), 'sql' => $sql]]]; }
/** * @return void */ protected function updateCache() { if (!isset(static::$data[$this->cacheKey])) { static::$data[$this->cacheKey] = []; } $dependency = Yii::$container->get(DbDependency::className(), [], ['sql' => ActiveParam::CACHE_DEPENDENCY, 'params' => [':category' => $this->uniqueId], 'reusable' => true]); if (Yii::$app->cache->set($this->cacheKey, static::$data[$this->cacheKey], 0, $dependency)) { Yii::info('Active params for component ' . get_class($this->owner) . " '{$this->uniqueId}' cached successfully", __METHOD__); return; } Yii::warning('Caching active params for component ' . get_class($this->owner) . " '{$this->uniqueId}' failed", __METHOD__); }
public function behaviors() { $behaviors = parent::behaviors(); $behaviors['responseCache'] = ['class' => ResponseCache::className(), 'actions' => ['nav-lang-item'], 'variations' => [Yii::$app->request->get('navId', 0), Yii::$app->request->get('langId', 0)], 'dependency' => ['class' => DbDependency::className(), 'sql' => 'SELECT timestamp_update FROM cms_nav_item WHERE lang_id=:lang_id AND nav_id=:nav_id', 'params' => [':lang_id' => Yii::$app->request->get('langId', 0), ':nav_id' => Yii::$app->request->get('navId', 0)]]]; return $behaviors; }