Browse Source

Settings -> Config for Cache namespace

AD7six 12 years ago
parent
commit
3f01f75550

+ 18 - 4
src/Cache/CacheEngine.php

@@ -169,10 +169,24 @@ abstract class CacheEngine {
 /**
  * Cache Engine config
  *
- * @return array config
- */
-	public function config() {
-		return $this->_config;
+ * If called with no arguments, returns the full config array
+ * Otherwise returns the config for the specified key
+ *
+ * Usage:
+ * {{{
+ * $instance->config(); will return full config
+ * $instance->config('duration'); will return configured duration
+ * $instance->config('notset'); will return null
+ * }}}
+ *
+ * @param string|null $key to return
+ * @return mixed array or config value
+ */
+	public function config($key = null) {
+		if ($key === null) {
+			return $this->_config;
+		}
+		return isset($this->_config[$key]) ? $this->_config[$key] : null;
 	}
 
 /**

+ 1 - 1
tests/TestCase/Cache/CacheTest.php

@@ -275,7 +275,7 @@ class CacheTest extends TestCase {
 
 /**
  * test that configured returns an array of the currently configured cache
- * settings
+ * config
  *
  * @return void
  */

+ 4 - 4
tests/TestCase/Cache/Engine/MemcachedEngineTest.php

@@ -242,14 +242,14 @@ class MemcachedEngineTest extends TestCase {
 		);
 
 		$Memcached = new TestMemcachedEngine();
-		$settings = array(
+		$config = array(
 			'engine' => 'Memcached',
 			'servers' => array('127.0.0.1:11211'),
 			'persistent' => false,
 			'serialize' => 'msgpack'
 		);
 
-		$Memcached->init($settings);
+		$Memcached->init($config);
 		$this->assertEquals(Memcached::SERIALIZER_MSGPACK, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER));
 	}
 
@@ -290,7 +290,7 @@ class MemcachedEngineTest extends TestCase {
 		);
 
 		$Memcached = new TestMemcachedEngine();
-		$settings = array(
+		$config = array(
 			'engine' => 'Memcached',
 			'servers' => array('127.0.0.1:11211'),
 			'persistent' => false,
@@ -300,7 +300,7 @@ class MemcachedEngineTest extends TestCase {
 		$this->setExpectedException(
 			'Cake\Error\Exception', 'msgpack is not a valid serializer engine for Memcached'
 		);
-		$Memcached->init($settings);
+		$Memcached->init($config);
 	}
 
 /**