Search code examples
phpcachingyiiquery-cache

Yii query cache forcing cache also for upcoming model call


I'm having a strange problem in my application (Yii Framework 1.1.8).

I called a function as follows:

UserDataModel::model()->cache(3600, $dependency)->getAttributes();

After calling this function I called another model and fetched the data.

ProfileModel::model()->findAll();

To my surprise, ProfileModel was also cached. When I remove the first line (UserDataModel), the ProfileModel fetches the uncached data. Since both models are different, why first model is forcing cache for the next model call ?

Is there anything wrong with my implementation ?

Thanks.

Arfeen


Solution

  • I hope I can help you out, as I can see you are not specifying the third parameter in the cache which indicates the number of queries to be cached. My guess is that if the dependency is true, everything from that line on to the bottom will be cached in the cfilecache created totally independent to the model. In fact I have cache which implements dependency on several tables so I can cache more than one query and in the third parameter I tell the cache how many queries will I save