Yii 1.1.7 Query Cache with Prepared Statements

Hey everyone,

Just wanted to know if anyone has experience with the new query caching in 1.1.7 and its compatibility with prepared statements. It appears that if I cache a query with placeholders, it caches any query using those placeholders, regardless of whether or not I bind different values to the query.

Does anyone know if there’s a way around this?

Also, with regards to caching ActiveRecords (which works much better), I have a large relational model structure setup, which I want to cache, but I’m not sure what $queryCount parameter to set. This is because my related models also have relations.


lecture has multiple meetings

lecture has multiple sections

section has multiple meetings

I want to find all lectures (and corresponding meetings) with my model, so I would use:

Lecture::model()->cache( 3600 )->with( ‘sections’, ‘sections.meetings’ )->findByAttributes( array( ‘course_id’ => xxx ) );

That only caches the initial fetch of the lecture. I understand there’s the $queryCount parameter, but I’m not sure if the lecture will have any sections. So, if I set the queryCount to 3, and the lecture has no sections, it will only execute two queries thus meaning that the next query I execute might be cached (which I don’t want).

Any ideas?

Side note - I keep creating duplicate posts because the forums are giving me an SQL error after approximately a 20 second timeout or so when pressing the post button, bringing me back to the edit page. Just a heads up to whoever manages.

Solution found. To anyone else who wants to use this:


‘enableParamLogging’ => true

For your CDbConnection instances in your config file.

I just checked in a fix for this issue. Using query caching shouldn’t require ‘enableParamLogging’=>true.

Awesome. Thanks for the rapid response! Do you have any answers to the second part of my question?

You can call Lecture::model()->cache(0); afterwards to ensure query caching is turned off.