|
- <?php
-
-
- namespace yii\caching;
-
- use Yii;
- use yii\base\InvalidConfigException;
- use yii\db\Connection;
- use yii\di\Instance;
-
-
- class DbDependency extends Dependency
- {
-
-
- public $db = 'db';
-
-
- public $sql;
-
-
- public $params = [];
-
-
-
-
- protected function generateDependencyData($cache)
- {
- $db = Instance::ensure($this->db, Connection::className());
- if ($this->sql === null) {
- throw new InvalidConfigException('DbDependency::sql must be set.');
- }
-
- if ($db->enableQueryCache) {
-
- $db->enableQueryCache = false;
- $result = $db->createCommand($this->sql, $this->params)->queryOne();
- $db->enableQueryCache = true;
- } else {
- $result = $db->createCommand($this->sql, $this->params)->queryOne();
- }
-
- return $result;
- }
- }
|