How to flush db query cache in yii2? -


how handle when changes happen in specific table records ?

public static function getairportwithcache($iata_code){                $result = airports::getdb()->cache(function ($db) use ($iata_code){                      $res = airports::find()                                ->where(['iata_code' => $iata_code])                                ->limit(1)                                ->asarray()                                ->one();                      return $res;               });               return $result;         } 

you should use \yii\caching\dbdependency, e.g. :

public static function getairportwithcache($iata_code){     // example if airports count change, update cache     $dependency = new \yii\caching\dbdependency(['sql' => 'select count(*) ' . 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; } 

read more...


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -