I’m sorry. I think I was wrong in the previous post.
The reference seems to say that it’s not necessary to specify ‘queryCacheID’ explicitly when you use default cache component (that is ‘cache’) for it.
I guess you can not get the right value by var_dump($dependency->getHasChanged()).
I think the method won’t have meaning when you call it directly. It should be called by the cache component that need to check the dependency.
The cache dependency definition and its result are saved together with the cache content into the cache entry. And the cache dependency definition will be re-evaluated to check if the result is still the same or not when they are loaded with the cache content next time when you access the cache entry.
So, checking getHasChanged() right after you’ve created the dependency will have no meaning …
$dependency = new CDbCacheDependency('SELECT MAX(id) FROM tbl_points_log');
$sql='SELECT SUM( point) as user_point FROM tbl_points_log left join tbl_action on tbl_action.id = tbl_points_log.action_type_id where user_id='.Yii::app()->user->id;
$user_point = Yii::app()->db->cache(1000, $dependency)->createCommand($sql)->queryAll();
I have checked ‘/framework/db/CDbConnection.php’. Please take a look at it yourself.
You will notice that these properties are defined and have their default values regarding the caching.
We have to override schemaCachingDuration and queryCachingDuration if we want schema caching and query caching as you did in your configuration. But we don’t need to explicitly set schemaCacheID and queryCacheID if we are going to use ‘cache’ for cache component.
We can use multiple cache components and we may name them as we like, for example: