Zend Framework: Cache Database Table Schemes

If you’re familiar with Zend Framework, you should know how to turn your database tables into models. Simply extend the Zend_Db_Table class. This is the very general example. There are lots of variations how to name the model classes and what member variables they can have.

<?
class User extends Zend_Db_Table
{}

The question is …

The question is how the framework knows what columns there are in a given table. That’s done by PHP on every call of the class, and the question is: isn’t that too slow? Yes it is and there’s a solution – to cache the table’s schema:

Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);

Is there any problem?

Why it isn’t a default behavior when it’s so good? Because you’ve first to setup the cache, which is not always permitted – at least you’ve to have writing permissions. And on the second place if you’re rapidly developing the system and you change the database schema too frequently, you’ve to clear the cache every time. So it’s a good solution for the production server, but you can skip it while developing.

Leave a Reply

Your email address will not be published. Required fields are marked *