and so on. My problem is, that if the view is already cached, the Controller will still do the findAllByAttributes and query the SQL, although it won’t be needed in the view, as it comes from the cache.
How could I make the controller check whether the view is cached and then skip all queries?
Well, data/query caching works independently from fragment caching. There are situations where it can make sense to combine those caching methods. However, my impression is that you should resort to query caching exclusively in your case. Pay special attention to the subsection "Using Query Caching with ActiveRecord."
…or you can use data provider pattern which prepares query but do not execute it unless there is real need to fetch data.
the difference is that with dataprovider whole rendered HTML part will be cached, and with query cache it will be still rendered on every request. It is important when you use lazy loading.
So be careful with lazy loading, which you are using - you are printing “$place->foreign_user->name”, but you did not query for Places::model->with(‘foreign_user’). This way you will stil have queries for each ‘foreign_user’ sparately…