How to clear schema cache?

If you have schemaCachingDuration turned on - you need a way to clear the cache. I can think about changing cache_id. Is there any other way?

For file cache you can delete files, what about memcache?

You can set the number of seconds that table metadata can remain valid in cache in your main.php file.


'db'=>array(

        ............

        'schemaCachingDuration'=>3600, // number of seconds

        ............

),

'cache'=>array(

        'class' => 'CFileCache',

),



http://www.yiiframework.com/doc/guide/1.1/en/caching.overview

So you reply is “Wait until schemaCachingDuration expires”. But I’m asking about how to CLEAR cache when you need chema changes to come live NOW.

As far as I know, there is no mechanism to clear the cache "schemaCachingDuration".

You can use Yii:: app () ->cache->flush()

That worked, thanks!

For those people who are also looking for a decent answer because Yii::app()->cache->flush() clears all the cache.

To refresh the database cache :




// Load all tables of the application in the schema

Yii::app()->db->schema->getTables();

// clear the cache of all loaded tables

Yii::app()->db->schema->refresh();



If you want to refresh only one table, you can also do :




Yii::app()->db->schema->getTable('tablename', true);



1 Like

If CFileCache is used for caching, then deleting the files in protected/runtime/cache/ would clear the cache.

This saved my time. Thanks

Thank you so much.

This is great and works, thanks.

Though I would like to point out that 1st command will cache schema for all tables in databases even if they are not used in application.

‘Remove’ file cache:


Yii::app()->cache->set($id_file_cache, false);