ActiveRecord metadata caching persistence

Hello,

Our (big) application relies heavily on AR and while looking at SQL traces I see the sql code for metadata loading. But this thing is done at every request. It is not really a problem since there’s no other way around it, but it can become a problem on a high load application when every db hit must be well thought.

How about an new yii feature, a command line script that reads the metadata for each AR from database, generates a PHP file for it, and then instead of reading the metadata from db it is readily available by including the generated php file. I see not drawbacks, as fast as possible, friendly to APC and other caching systems…

Of course it should be disabled by default, it is meaningless to use it on a development database, but on production it would be a good performance improvement.

Opinios?

Thanks,

-soso

Did you check this? http://www.yiiframework.com/doc/api/CDbConnection#schemaCachingDuration-detail

No, will check it, sorry for the noise! :rolleyes:

The metadata caching certain works quite well, BUT it cannot be used on servers that don’t have some sort of caching installed. The problem there in turn is that if you want to run your application on a shared server, often the shared servers will not have any caching installed because it clashes with the Zend and IonCube encoder modules. So, I think it would be a VERY useful feature to have Yii generate and store the metadata in PHP files (the use of which is of course optional). Having done testing, metadata caching improves performance SIGNIFICANTLY and for that reason a solution that would make Yii perform better on shared servers would be very very helpful. In terms of implementation, all you really need to do is use file caching in these situations instead of memory based caching and all should work well.

You could try to configure CFileCache. It should work with every hoster and does what you described.