Skip to content
Permalink
Browse files

Making Cache::set() work with 2 or 3 parameters. Test cases added.

  • Loading branch information...
markstory committed Sep 18, 2010
1 parent 1eb746b commit b432e6097141340ee07943dcc713770969bde020
Showing with 27 additions and 3 deletions.
  1. +14 −3 cake/libs/cache.php
  2. +13 −0 cake/tests/cases/libs/cache.test.php
@@ -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;
}
@@ -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;
}
@@ -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
@@ -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.
You can’t perform that action at this time.