Cdbcachedependency Does Not Invalidate On Change (Yii 1.1.12)

I have the following


$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM ' . Post::model()->tableName());


$postsProvider = new CActiveDataProvider(Post::model()->cache(Yii::app()->params['cacheDuration'], $dependency, 1), array('criteria' => $criteria, 'pagination' => false));

the dependency seems not working , when i update a post and the update_time is changed the postsProvider is still cached and i have to flush cache to have it up to date

i checked that update_time was really changed in db and it’s ok.

i’m using yii 1.1.12

[color="#006400"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]

Usually you have to set 2 for the 3rd parameters when you want to apply query caching for CActiveDataProvider … one for querying the total row count, and the other for retrieving the row data. Because you set 1 for it, the main query will not be cached.

So I think your problem has some other cause.

I already tried setting 2 for the 3rd with the same result … and the best of all is that now I also tried disabling all caches in view and controller but I still get a cached result until I flush ??? I’ll try to debug deeper

I’ve found this: having another CActiveDataProvider using cache in the same controller will cause this issue… if I remove caching all works fine (the first will not be cached)

why using cache on another dataprovider that’s using another table cause the caching of the first?


  public function actionIndex() {

...

	$postsProvider = new CActiveDataProvider(Post::model()

    	array('criteria' => $criteria, 'pagination' => false));

...

	$reviewsProvider = new CActiveDataProvider(UserBook::model()->cache(Yii::app()->params['cacheDuration'], $userBookDependency, 2), 

    	array('criteria' => $criteria, 'pagination' => false));

...

		$this->render('index', array(

			'postsProvider' => $postsProvider, // THIS WILL BE CACHED TOO! WHY?

  	'reviewsProvider' => $reviewsProvider,

		));

}

Enabling tracing i saw that queries are not executed in the same order as I writed into the controller… why…

Hi manuel,

As my understandings go, caching is not executed in the level of CActiveDataProvider, nor in the CActiveRecord layer, but in the underlying layer of CDbConnection.

http://www.yiiframework.com/doc/api/1.1/CActiveRecord#cache-detail

When you set caching on an instance of CActiveDataProvider, it’s in fact a caching on the underlying db connection. So it can affect other instances of CActiveDataProvider that share the same db connection, just as you see in your case.

The executions of queries by CActiveDataProvider are triggered by its user, i.e., by a CGridView or a CListView. We tell the data providers what queries they should execute, but we don’t tell them when.