I’m sorry. When you are to use the default cache component (whose name is ‘cache’), then you will not need to specify ‘queryCacheID’ explicitly like the above.
Thanks for the reply. But still var_dump($dependency->getHasChanged()); always evaluates to true, even if I did no changes into database, so why is that? Is it because my query caching is not enabled?
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.
about $dependency->getHasChanged()
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.
[EDIT]
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();
var_dump($dependency->getHasChanged());
In short, I think the caching should be working fine, and you have to use some other means to check the functionality of cache dependency. Probably by sql logging.
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.
public $schemaCachingDuration=0;
public $schemaCacheID='cache';
public $queryCachingDuration=0;
public $queryCachingDependency;
public $queryCachingCount=0;
public $queryCacheID='cache';
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: