From bdd3225b419daa13c30faf966cb067ce999bacf8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 19 May 2014 22:13:09 -0400 Subject: [PATCH] Add forceRefresh option to describe This option lets you bypass cached data and always get fresh metadata. --- src/Console/Command/OrmCacheShell.php | 2 +- src/Database/Schema/Collection.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Console/Command/OrmCacheShell.php b/src/Console/Command/OrmCacheShell.php index fcc3b67a2b1..126e4e7949e 100644 --- a/src/Console/Command/OrmCacheShell.php +++ b/src/Console/Command/OrmCacheShell.php @@ -50,7 +50,7 @@ public function build($name = null) { } foreach ($tables as $table) { $this->_io->verbose('Building metadata cache for ' . $table); - $schema->describe($table); + $schema->describe($table, ['forceRefresh' => true]); } $this->out('Cache build complete'); } diff --git a/src/Database/Schema/Collection.php b/src/Database/Schema/Collection.php index 269b5136ae9..801ba39300d 100644 --- a/src/Database/Schema/Collection.php +++ b/src/Database/Schema/Collection.php @@ -86,14 +86,22 @@ public function listTables() { * Caching will be applied if `cacheMetadata` key is present in the Connection * configuration options. Defaults to _cake_model_ when true. * + * ### Options + * + * - `forceRefresh` - Set to true to force rebuilding the cached metadata. + * Defaults to false. + * * @param string $name The name of the table to describe. + * @param array $options The options to use, see above. * @return \Cake\Database\Schema\Table Object with column metadata. * @throws \Cake\Database\Exception when table cannot be described. */ - public function describe($name) { + public function describe($name, array $options) { + $options += ['forceRefresh' => false]; $cacheConfig = $this->cacheMetadata(); - if ($cacheConfig) { - $cacheKey = $this->cacheKey($name); + $cacheKey = $this->cacheKey($name); + + if (!empty($cacheConfig) && !$options['forceRefresh']) { $cached = Cache::read($cacheKey, $cacheConfig); if ($cached !== false) { return $cached;