You should just use \yii\caching\DbDependency
, for example.
public static function getAirportWithCache($iata_code){
$dependency = new \yii\caching\DbDependency(['sql' => 'SELECT COUNT(*) FROM ' . Airports::tableName()]);
$result = Airports::getDb()->cache(function ($db) use ($iata_code){
return Airports::find()
->where(['iata_code' => $iata_code])
->limit(1)
->asArray()
->one();
}, 0, $dependency);
return $result;
}
More details ...
source
share