12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?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;
- }
- }
|