If the query result changes, the dependency is considered as changed. The query is specified via the [[sql]] property. For more details and usage information on Cache, see the guide article on caching.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\caching\Dependency
 /**
  * @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 init()
 {
     parent::init();
     $this->prepareOptions();
     $this->buildQuery();
 }
 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]]];
 }
Exemplo n.º 4
0
 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;
 }