/** * 查询所有部门,返回object,缓存两小时、依赖部门数量变化 * @return \common\models\Department[] */ public static function findAllForObject() { $dependency = new DbDependency(['sql' => 'select count(*) from department']); $result = Department::getDb()->cache(function () { return Department::find()->all(); }, 2 * 3600, $dependency); return $result; }