I need help with caching Active Record data in Yii2.
In documentation has example:
$result = Customer::getDb()->cache(function ($db) {
return Customer::find()->where(['id' => 1])->one();
});
I understand that it need to implement the method in model class such a:
public static function getByPk($pk)
{
$result = self::getDb()->cache(function ($db) use ($pk) {
return self::find()->where(['id' => $pk])->one();
});
return $result;
}
If this query result was already cached in $result
will set value from cache, otherwise will execute query, correctly?
Also I have question about dependency, what dependency I can use for invalidation this cache value?