before create a account, i will find a record using model cache:
public function oneByFiled($value, $field = 'id')
{
return self::findFirst([
'conditions' => $field . ' = ?0',
'bind' => $value,
'cache' => ['key' => sprintf('%s:%s:%s', $this->getSource(), $field, $value), 'lifetime' => 600],
]);
}
then, create account record:
$userAccount = new UserAccounts();
$result = $userAccount->create([
'username' => $this->request->getPost('username'),
'password' => password_hash($this->request->getPost('password'), PASSWORD_DEFAULT),
]);
a new account record has been added to mysql, but when i call oneByFiled()
, it read from redis, return false.
how to insert a model cache record when create a row, and how to update a model cache record when update a mysql row?