Skip to content

Commit

Permalink
Add forceRefresh option to describe
Browse files Browse the repository at this point in the history
This option lets you bypass cached data and always get fresh metadata.
  • Loading branch information
markstory committed May 20, 2014
1 parent 041885d commit bdd3225
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/OrmCacheShell.php
Expand Up @@ -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('<success>Cache build complete</success>');
}
Expand Down
14 changes: 11 additions & 3 deletions src/Database/Schema/Collection.php
Expand Up @@ -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;
Expand Down

0 comments on commit bdd3225

Please sign in to comment.