Some light on CActiveDataProvider caching

Hi guys, I was hoping some of you might have some insight on how to solve this problem: I currently have a CActiveDataProvider with cache enabled using a CDbCacheDependency enabled. I really want to change this dependency, cause I don’t want to have to touch the database unless it’s completely necessary. I tried replacing the DbCacheDependency with a GlobalStateCacheDependency but my app is big and have many concurrent users, so it’s off the table. Then I tried CExpressionDependency with something like:

new CExpressionDependency(“Yii::app()->cache->get(’$key’) == ‘loadFromDatabase’”);

but it doesn’t seem to work as expected.

Then I tried (in my controller):




$duration = 1800;

if(Yii::app()->cache->get('$key') == 'loadFromDatabase'){

   $duration = 0; 

}

$dataProvider = new CActiveDataProvider(MyModal::model()->cache($duration, null, 2)));



but this doesn’t work either (works the first time that $duration = 0, but then the old value comes back).

Do you guys know ANY way to invalidate a CActiveDataProvider cache?

Thanks in advance!

Seems like the issue is that in CDbCommand, the queryInternal() method never deletes the value in cache if duration = 0 (I would expect that).

I decided to override this method by creating my own version of CDbCommand, CActiveRecord and CDbConnection. I will let you guys know how that goes.

Just to close this thread: I gave up on the approach of overriding some yii core files. I decided to create my own CacheDependency that checks my Redis server for changes in a given key. This is working nicely