Activerecord Table Schema Caching


Recently I was using active record, and faced some problem.

I wanted to configure my db component to cache table schema.

I put in my main.php, in db component parameter

schemaCachingDuration = 86400


According to the manual this option says to db to cache data about schema for 86400 seconds (one day), but when I switched on profiling I see this

system.db.CDbCommand.query(SHOW COLUMNS FROM some_table)

If I am not mistaking this request should be run once in a day, but Yii does it every controller load.

Maybe I missed something.

Have somebody faced this problem?

I had the same issue, did you find an answer Algez?

I was also trying to figure this out and found the solution.

You must enable caching for it to be effective.

Notice this:

If greater than 0 and the primary cache is enabled, the table metadata will be cached.

To set Caching, see Caching Overview

You will have to add Caching setting in Configuration, For Memcache you can use this:






                array('host'=>'server1', 'port'=>11211, 'weight'=>60),

                array('host'=>'server2', 'port'=>11211, 'weight'=>40),




Yep this is a solution, I found that out after 2-3 days.

I didn’t mension that my cache class was CDummyCache, that was the reason.

Thank you for reply.

By the way, memcache is the best way of caching only if you don’t run your project on Pentium 1. =)