Skip to content

Commit

Permalink
Making Cache::set() work with 2 or 3 parameters. Test cases added.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 18, 2010
1 parent 1eb746b commit b432e60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cake/libs/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,23 @@ protected static function _loadEngine($name, $plugin = null) {
* Temporarily change settings to current config options. if no params are passed, resets settings if needed
* Cache::write() will reset the configuration changes made
*
* Can be called with 2 or 3 parameters. To set multiple values at once.
*
* `Cache::set(array('duration' => '+30 minutes'), 'my_config');`
*
* Or to set one value.
*
* `Cache::set('duration', '+30 minutes', 'my_config');`
*
* @param mixed $settings Optional string for simple name-value pair or array
* @param string $value Optional for a simple name-value pair
* @param string $config The configuration name you are changing. Defaults to 'default'
* @return array Array of settings.
*/
public static function set($settings = array(), $value = null, $config = 'default') {
if (is_array($settings) && $value !== null) {
$config = $value;
}
if (!isset(self::$_config[$config]) || !isset(self::$_engines[$config])) {
return false;
}
Expand Down Expand Up @@ -417,11 +428,11 @@ public static function clear($check = false, $config = 'default') {
/**
* Check if Cache has initialized a working config for the given name.
*
* @param string $engine Name of the engine
* @param string $engine Name of the engine, Defaults to default
* @param string $config Name of the configuration setting
* @return bool Whether or not the config name has been initialized.
*/
public static function isInitialized($name) {
public static function isInitialized($name = 'default') {
if (Configure::read('Cache.disable')) {
return false;
}
Expand All @@ -431,7 +442,7 @@ public static function isInitialized($name) {
/**
* Return the settings for the named cache engine.
*
* @param string $engine Name of the configuration to get settings for.
* @param string $engine Name of the configuration to get settings for. Defaults to 'default'
* @return array list of settings for this engine
* @see Cache::config()
* @access public
Expand Down
13 changes: 13 additions & 0 deletions cake/tests/cases/libs/cache.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,17 @@ function testSet() {
Cache::set($_cacheSet);
}

/**
* test set() parameter handling for user cache configs.
*
* @return void
*/
function testSetOnAlternateConfigs() {
Cache::config('file_config', array('engine' => 'File', 'prefix' => 'test_file_'));
Cache::set(array('duration' => '+1 year'), 'file_config');
$settings = Cache::settings('file_config');

$this->assertEquals('test_file_', $settings['prefix']);
$this->assertEquals(31536000, $settings['duration']);
}
}

0 comments on commit b432e60

Please sign in to comment.