Dear all,
I’m new in our forum. I’ve stared with Yii Framework about 3 month ago.
Today I have a question, I tried to search forum, wiki and google but could not able to find a good solution.
I want to use cache for my profile, so I enabled cache class in config file (CFileCache and/or CMemcached).
It’s working. But I met problem when processing user password changing and user profile changing.
I used 2 ways to use caching system:
//The same for find, findAll, findBySql...
User::model()->cache($time)->findByPk(x)
and
User::model()->findByPk(x)
//The same for find, findAll, findBySql...
In Model User
public function findByPk($pk, $condition = '', $params = array()) {
$cacheKey = 'user:'.$pk.':'.$condition.':'.serialize($params);
$cache = Yii::app()->cache;
if ($cacheKey === null)
{
$result = parent::findByPk($pk, $condition, $params);
}
else if ($cache->get($cacheKey) === false && $cacheKey !== null)
{
$result = parent::findByPk($pk, $condition, $params);
$cache->set($cacheKey, $result, Yii::app()->params['cacheExpire']);
}
else
{
$result = $cache->get($cacheKey);
}
return $result;
}
In both ways above. I cannot find the solution to delete cached key that belong to user when he/she change password or his own information in profile.
Looking forward for your helps.
Thanks.