CDbCacheDependency with dynamic amount of relations

I built a web application, that uses lazy loading of related models very intensively.

Now I have the problem, that the request of any page takes a very long time (several seconds). Therefore I need some caching functionality.

But as I use the same core code with different themes, which vary in what attributes should be displayed, I do not yet know in controller when I do my database queries via CDbCritieria which relations will be additionally loaded and which not. Besides there might also be some plugins for some application instances, which add further relations, for which I cannot decide to load or not to load in advance.

For example I have a model "Event" with the following relations:

public function relations() {

	return array(

		'production' => array(self::BELONGS_TO, 'Production', 'production_id'),

		'prices' => array(Event::HAS_MANY, 'EventPrice', 'event_id'),

		'venue' => array(Event::BELONGS_TO, 'Venue', 'venue_id')



While I can assure that the production relation should always be loaded together with the Event, the prices and venue models should only be loaded, when the view requires some related attributes, otherwise not.)

I would like to use Yii’s built-in caching with dependency like

$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM {{event}}');

$events = Event::model()->cache(1000, $dependency, 2)->with('production')->findAll();

but this requires me to define the amount of queries to be cached in advance, which I can’t, because I do not know which relations will be lazily loaded.

If I choose the third parameter too low, the caching takes no impact and, if I set it to a very high value, it caches queries even from other contexts.

Is there any possibility to define caching for the current and all associated queries (by lazy loaded relations)?

Or can I somehow - if I set the third parameter to PHP_INT_MAX - break the caching after my main statement?

Any model in my application has an update_time column which should be the reference point for the caching. Perhaps it is possible to define some caching on ActiveRecord base?

Is there anyone who can give me advice?

I moved this question to the 1.1.x-Forum. Sorry for selecting this part of forum.