From 3e7249fb9a9c0b140fa65399941a1a3a0d4902e6 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sat, 10 Nov 2012 15:49:15 +0100 Subject: [PATCH 01/13] UnitTests for empty namespaces --- test/Storage/Adapter/CommonAdapterTest.php | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/Storage/Adapter/CommonAdapterTest.php b/test/Storage/Adapter/CommonAdapterTest.php index 12a5cdece..d6bdad1f7 100644 --- a/test/Storage/Adapter/CommonAdapterTest.php +++ b/test/Storage/Adapter/CommonAdapterTest.php @@ -397,8 +397,10 @@ public function testGetMetadatasReturnsEmptyArrayIfNonReadable() $this->assertEquals(array(), $this->_storage->getMetadatas(array('key'))); } - public function testSetGetHasAndRemoveItem() + public function testSetGetHasAndRemoveItemWithoutNamespace() { + $this->_storage->getOptions()->setNamespace(''); + $this->assertTrue($this->_storage->setItem('key', 'value')); $this->assertEquals('value', $this->_storage->getItem('key')); $this->assertTrue($this->_storage->hasItem('key')); @@ -408,8 +410,10 @@ public function testSetGetHasAndRemoveItem() $this->assertNull($this->_storage->getItem('key')); } - public function testSetGetHasAndRemoveItems() + public function testSetGetHasAndRemoveItemsWithoutNamespace() { + $this->_storage->getOptions()->setNamespace(''); + $items = array( 'key1' => 'value1', 'key2' => 'value2', @@ -930,6 +934,16 @@ public function testClearByPrefix() $this->assertTrue($this->_storage->hasItem('test')); } + public function testClearByPrefixThrowsInvalidArgumentExceptionOnEmptyPrefix() + { + if (!($this->_storage instanceof ClearByPrefixInterface)) { + $this->markTestSkipped("Storage doesn't implement ClearByPrefixInterface"); + } + + $this->setExpectedException('Zend\Cache\Exception\InvalidArgumentException'); + $this->_storage->clearByPrefix(''); + } + public function testClearByNamespace() { if (!($this->_storage instanceof ClearByNamespaceInterface)) { @@ -964,6 +978,16 @@ public function testClearByNamespace() $this->assertFalse($this->_storage->hasItem('key2')); } + public function testClearByNamespaceThrowsInvalidArgumentExceptionOnEmptyNamespace() + { + if (!($this->_storage instanceof ClearByNamespaceInterface)) { + $this->markTestSkipped("Storage doesn't implement ClearByNamespaceInterface"); + } + + $this->setExpectedException('Zend\Cache\Exception\InvalidArgumentException'); + $this->_storage->clearByNamespace(''); + } + public function testClearExpired() { if (!($this->_storage instanceof ClearExpiredInterface)) { From f5959cf4e8e6398c3ac8bb8cf9138ca4cf223abc Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Tue, 14 Aug 2012 00:22:23 +0200 Subject: [PATCH 02/13] ZendServerDisk: fixed getTotalSpace and getAvailableSpace --- src/Storage/Adapter/ZendServerDisk.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Storage/Adapter/ZendServerDisk.php b/src/Storage/Adapter/ZendServerDisk.php index 9d5b52812..7ff994226 100644 --- a/src/Storage/Adapter/ZendServerDisk.php +++ b/src/Storage/Adapter/ZendServerDisk.php @@ -93,8 +93,8 @@ public function clearByNamespace($namespace) */ public function getTotalSpace() { - if ($this->totalSpace !== null) { - $path = $this->getOptions()->getCacheDir(); + if ($this->totalSpace === null) { + $path = ini_get('zend_datacache.disk.save_path'); ErrorHandler::start(); $total = disk_total_space($path); @@ -102,6 +102,8 @@ public function getTotalSpace() if ($total === false) { throw new Exception\RuntimeException("Can't detect total space of '{$path}'", 0, $error); } + + $this->totalSpace = $total; } return $this->totalSpace; } @@ -116,7 +118,7 @@ public function getTotalSpace() */ public function getAvailableSpace() { - $path = $this->getOptions()->getCacheDir(); + $path = ini_get('zend_datacache.disk.save_path'); ErrorHandler::start(); $avail = disk_free_space($path); From a11dd8a5c2db138a6445a54813c85becd3ef81ca Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Tue, 14 Aug 2012 00:27:15 +0200 Subject: [PATCH 03/13] AbstractZendServer: added missing argument on calling zdcFetchMulti --- src/Storage/Adapter/AbstractZendServer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Storage/Adapter/AbstractZendServer.php b/src/Storage/Adapter/AbstractZendServer.php index 457b06562..3c48de290 100644 --- a/src/Storage/Adapter/AbstractZendServer.php +++ b/src/Storage/Adapter/AbstractZendServer.php @@ -111,7 +111,7 @@ protected function internalHasItems(array & $normalizedKeys) { $namespace = $this->getOptions()->getNamespace(); if ($namespace === '') { - return array_keys($this->zdcFetchMulti()); + return array_keys($this->zdcFetchMulti($normalizedKeys)); } $prefix = $namespace . self::NAMESPACE_SEPARATOR; @@ -144,7 +144,7 @@ protected function internalGetMetadatas(array & $normalizedKeys) { $namespace = $this->getOptions()->getNamespace(); if ($namespace === '') { - $result = $this->zdcFetchMulti(); + $result = $this->zdcFetchMulti($normalizedKeys); return array_fill_keys(array_keys($result), array()); } From f047d34ebf0c73fb6ab1effebd2640f3f108f445 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Wed, 31 Oct 2012 21:13:58 +0100 Subject: [PATCH 04/13] removed not needed use statement --- src/Storage/Adapter/Memcached.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Storage/Adapter/Memcached.php b/src/Storage/Adapter/Memcached.php index 71e3d98da..1b77e91f5 100644 --- a/src/Storage/Adapter/Memcached.php +++ b/src/Storage/Adapter/Memcached.php @@ -16,7 +16,6 @@ use Zend\Cache\Exception; use Zend\Cache\Storage\AvailableSpaceCapableInterface; use Zend\Cache\Storage\Capabilities; -use Zend\Cache\Storage\Event; use Zend\Cache\Storage\FlushableInterface; use Zend\Cache\Storage\TotalSpaceCapableInterface; From 0152a1177cecea35bb11898429e12a377da73bdf Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Wed, 31 Oct 2012 21:15:41 +0100 Subject: [PATCH 05/13] fixed wrong doc-comment --- src/Storage/Adapter/Memcached.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Storage/Adapter/Memcached.php b/src/Storage/Adapter/Memcached.php index 1b77e91f5..3939564ca 100644 --- a/src/Storage/Adapter/Memcached.php +++ b/src/Storage/Adapter/Memcached.php @@ -59,7 +59,6 @@ class Memcached extends AbstractAdapter implements /** * The namespace prefix - * (Gets updated on change one of the options "namespace" or "namespace_separator") * * @var string */ From e6795453730e6836b35a41c19a24842e8b2ec240 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Mon, 12 Nov 2012 14:40:12 +0100 Subject: [PATCH 06/13] Added E_USER_DEPRECATED errors --- src/Storage/Adapter/MemcachedOptions.php | 33 ++++++++++- .../Adapter/MemcachedResourceManager.php | 2 +- test/Storage/Adapter/MemcachedTest.php | 57 +++++++++++++++++-- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/Storage/Adapter/MemcachedOptions.php b/src/Storage/Adapter/MemcachedOptions.php index 4889a7c3d..1eaf1f1f4 100644 --- a/src/Storage/Adapter/MemcachedOptions.php +++ b/src/Storage/Adapter/MemcachedOptions.php @@ -100,6 +100,12 @@ public function getNamespaceSeparator() */ public function setMemcachedResource(MemcachedResource $memcachedResource = null) { + trigger_error( + 'This method is deprecated and will be removed in the feature' + . ', please use the resource manager instead', + E_USER_DEPRECATED + ); + if ($memcachedResource !== null) { $this->triggerOptionEvent('memcached_resource', $memcachedResource); $resourceManager = $this->getResourceManager(); @@ -117,6 +123,12 @@ public function setMemcachedResource(MemcachedResource $memcachedResource = null */ public function getMemcachedResource() { + trigger_error( + 'This method is deprecated and will be removed in the feature' + . ', please use the resource manager instead', + E_USER_DEPRECATED + ); + return $this->resourceManager->getResource($this->getResourceId()); } @@ -208,11 +220,18 @@ public function setPersistentId($persistentId) */ public function addServer($host, $port = 11211, $weight = 0) { + trigger_error( + 'This method is deprecated and will be removed in the feature' + . ', please use the resource manager instead', + E_USER_DEPRECATED + ); + $this->getResourceManager()->addServer($this->getResourceId(), array( 'host' => $host, 'port' => $port, 'weight' => $weight )); + return $this; } @@ -263,7 +282,13 @@ public function setLibOptions(array $libOptions) */ public function setLibOption($key, $value) { - $this->getResourceManager()->setLibOptions($this->getResourceId(), $key, $value); + trigger_error( + 'This method is deprecated and will be removed in the feature' + . ', please use "lib_options" or the resource manager instead', + E_USER_DEPRECATED + ); + + $this->getResourceManager()->setLibOption($this->getResourceId(), $key, $value); return $this; } @@ -288,6 +313,12 @@ public function getLibOptions() */ public function getLibOption($key) { + trigger_error( + 'This method is deprecated and will be removed in the feature' + . ', please use "lib_options" or the resource manager instead', + E_USER_DEPRECATED + ); + return $this->getResourceManager()->getLibOption($this->getResourceId(), $key); } } diff --git a/src/Storage/Adapter/MemcachedResourceManager.php b/src/Storage/Adapter/MemcachedResourceManager.php index 7c32890ad..e19e195f0 100644 --- a/src/Storage/Adapter/MemcachedResourceManager.php +++ b/src/Storage/Adapter/MemcachedResourceManager.php @@ -270,7 +270,7 @@ public function getLibOptions($id) */ public function setLibOption($id, $key, $value) { - return $this->setLibOptions($id, array($libOptions)); + return $this->setLibOptions($id, array($key => $value)); } /** diff --git a/test/Storage/Adapter/MemcachedTest.php b/test/Storage/Adapter/MemcachedTest.php index f278c6fce..651a12a3a 100644 --- a/test/Storage/Adapter/MemcachedTest.php +++ b/test/Storage/Adapter/MemcachedTest.php @@ -31,11 +31,18 @@ public function setUp() $this->markTestSkipped("Memcached extension is not loaded"); } - $this->_options = new Cache\Storage\Adapter\MemcachedOptions(); + $this->_options = new Cache\Storage\Adapter\MemcachedOptions(array( + 'resource_id' => __CLASS__ + )); + if (defined('TESTS_ZEND_CACHE_MEMCACHED_HOST') && defined('TESTS_ZEND_CACHE_MEMCACHED_PORT')) { - $this->_options->addServer(TESTS_ZEND_CACHE_MEMCACHED_HOST, TESTS_ZEND_CACHE_MEMCACHED_PORT); + $this->_options->getResourceManager()->setServers(__CLASS__, array( + array(TESTS_ZEND_CACHE_MEMCACHED_HOST, TESTS_ZEND_CACHE_MEMCACHED_PORT) + )); } elseif (defined('TESTS_ZEND_CACHE_MEMCACHED_HOST')) { - $this->_options->addServer(TESTS_ZEND_CACHE_MEMCACHED_HOST); + $this->_options->getResourceManager()->setServers(__CLASS__, array( + array(TESTS_ZEND_CACHE_MEMCACHED_HOST) + )); } $this->_storage = new Cache\Storage\Adapter\Memcached(); @@ -45,13 +52,25 @@ public function setUp() parent::setUp(); } + /** + * @deprecated + */ public function testOptionsAddServer() { $options = new Cache\Storage\Adapter\MemcachedOptions(); + + $deprecated = false; + set_error_handler(function () use (& $deprecated) { + $deprecated = true; + }, E_USER_DEPRECATED); + $options->addServer('127.0.0.1', 11211); $options->addServer('localhost'); $options->addServer('domain.com', 11215); + restore_error_handler(); + $this->assertTrue($deprecated, 'Missing deprecated error'); + $servers = array( array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 0), array('host' => 'localhost', 'port' => 11211, 'weight' => 0), @@ -111,7 +130,6 @@ public function getServersDefinitions() } /** - * * @dataProvider getServersDefinitions */ public function testOptionSetServers($servers, $expectedServers) @@ -129,7 +147,9 @@ public function testLibOptionsSet() 'COMPRESSION' => false )); - $this->assertEquals($options->getLibOption(\Memcached::OPT_COMPRESSION), false); + $this->assertEquals($options->getResourceManager()->getLibOption( + $options->getResourceId(), \Memcached::OPT_COMPRESSION + ), false); $memcached = new Cache\Storage\Adapter\Memcached($options); $this->assertEquals($memcached->getOptions()->getLibOptions(), array( @@ -137,6 +157,33 @@ public function testLibOptionsSet() )); } + /** + * @deprecated + */ + public function testLibOptionSet() + { + $options = new Cache\Storage\Adapter\MemcachedOptions(); + + $deprecated = false; + set_error_handler(function () use (& $deprecated) { + $deprecated = true; + }, E_USER_DEPRECATED); + + $options->setLibOption('COMPRESSION', false); + + restore_error_handler(); + $this->assertTrue($deprecated, 'Missing deprecated error'); + + $this->assertEquals($options->getResourceManager()->getLibOption( + $options->getResourceId(), \Memcached::OPT_COMPRESSION + ), false); + + $memcached = new Cache\Storage\Adapter\Memcached($options); + $this->assertEquals($memcached->getOptions()->getLibOptions(), array( + \Memcached::OPT_COMPRESSION => false + )); + } + public function tearDown() { if ($this->_storage) { From ada477021355a99e308accafe37f350488f47e0b Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Mon, 12 Nov 2012 19:55:59 +0100 Subject: [PATCH 07/13] Fixed use statement --- src/Storage/Adapter/MemcachedResourceManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Adapter/MemcachedResourceManager.php b/src/Storage/Adapter/MemcachedResourceManager.php index e19e195f0..acb8082b3 100644 --- a/src/Storage/Adapter/MemcachedResourceManager.php +++ b/src/Storage/Adapter/MemcachedResourceManager.php @@ -10,8 +10,8 @@ namespace Zend\Cache\Storage\Adapter; -use ClassReflection; use Memcached as MemcachedResource; +use ReflectionClass; use Traversable; use Zend\Cache\Exception; use Zend\Stdlib\ArrayUtils; From 161ad3288b565420796c956910859dd0f56c0f9e Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Fri, 23 Nov 2012 23:12:43 +0100 Subject: [PATCH 08/13] Add pattern & storage cache factory --- src/Service/PatternCacheFactory.php | 35 +++++++++++++++++ src/Service/StorageCacheFactory.php | 35 +++++++++++++++++ test/Service/PatternCacheFactoryTest.php | 46 ++++++++++++++++++++++ test/Service/StorageCacheFactoryTest.php | 49 ++++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 src/Service/PatternCacheFactory.php create mode 100644 src/Service/StorageCacheFactory.php create mode 100644 test/Service/PatternCacheFactoryTest.php create mode 100644 test/Service/StorageCacheFactoryTest.php diff --git a/src/Service/PatternCacheFactory.php b/src/Service/PatternCacheFactory.php new file mode 100644 index 000000000..85ef02ef5 --- /dev/null +++ b/src/Service/PatternCacheFactory.php @@ -0,0 +1,35 @@ +get('Config'); + $cacheConfig = isset($config['cache_pattern']) ? $config['cache_pattern'] : array(); + $cache = PatternFactory::factory($cacheConfig); + + return $cache; + } +} diff --git a/src/Service/StorageCacheFactory.php b/src/Service/StorageCacheFactory.php new file mode 100644 index 000000000..c1ed072d9 --- /dev/null +++ b/src/Service/StorageCacheFactory.php @@ -0,0 +1,35 @@ +get('Config'); + $cacheConfig = isset($config['cache']) ? $config['cache'] : array(); + $cache = StorageFactory::factory($cacheConfig); + + return $cache; + } +} diff --git a/test/Service/PatternCacheFactoryTest.php b/test/Service/PatternCacheFactoryTest.php new file mode 100644 index 000000000..aaea53c47 --- /dev/null +++ b/test/Service/PatternCacheFactoryTest.php @@ -0,0 +1,46 @@ +sm = new ServiceManager(); + $this->sm->setService('Config', array('cache_pattern' => 'capture')); + $this->sm->setFactory('PatternCacheFactory', 'Zend\Cache\Service\PatternCacheFactory'); + } + + public function tearDown() + { + Cache\StorageFactory::resetAdapterPluginManager(); + Cache\StorageFactory::resetPluginManager(); + } + + public function testCreateServiceCache() + { + $cache = $this->sm->get('PatternCacheFactory'); + $this->assertEquals('Zend\Cache\Pattern\CaptureCache', get_class($cache)); + } +} diff --git a/test/Service/StorageCacheFactoryTest.php b/test/Service/StorageCacheFactoryTest.php new file mode 100644 index 000000000..2fa9597d7 --- /dev/null +++ b/test/Service/StorageCacheFactoryTest.php @@ -0,0 +1,49 @@ +sm = new ServiceManager(); + $this->sm->setService('Config', array('cache' => array( + 'adapter' => 'Memory', + 'plugins' => array('Serializer', 'ClearExpiredByFactor'), + ))); + $this->sm->setFactory('CacheFactory', 'Zend\Cache\Service\StorageCacheFactory'); + } + + public function tearDown() + { + Cache\StorageFactory::resetAdapterPluginManager(); + Cache\StorageFactory::resetPluginManager(); + } + + public function testCreateServiceCache() + { + $cache = $this->sm->get('CacheFactory'); + $this->assertEquals('Zend\Cache\Storage\Adapter\Memory', get_class($cache)); + } +} From b6bd49e02ab0745fbc1d885b5db94c040cfe12a8 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Mon, 26 Nov 2012 10:17:27 +0100 Subject: [PATCH 09/13] Simplified Apc::getIterator --- src/Storage/Adapter/Apc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Storage/Adapter/Apc.php b/src/Storage/Adapter/Apc.php index b5beb8803..870f880df 100644 --- a/src/Storage/Adapter/Apc.php +++ b/src/Storage/Adapter/Apc.php @@ -141,9 +141,9 @@ public function getIterator() { $options = $this->getOptions(); $namespace = $options->getNamespace(); - if ($namespace === '') { - $pattern = null; - } else { + $prefix = ''; + $pattern = null; + if ($namespace !== '') { $prefix = $namespace . $options->getNamespaceSeparator(); $pattern = '/^' . preg_quote($prefix, '/') . '/'; } From 1386257509978eb7290c2974aa025fdc4eb97cb6 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sat, 10 Nov 2012 16:34:37 +0100 Subject: [PATCH 10/13] XCache: empty namespace disabled namespace suport --- src/Storage/Adapter/XCache.php | 71 +++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/src/Storage/Adapter/XCache.php b/src/Storage/Adapter/XCache.php index c4baa4c47..7c9482c5b 100644 --- a/src/Storage/Adapter/XCache.php +++ b/src/Storage/Adapter/XCache.php @@ -165,6 +165,11 @@ public function getAvailableSpace() */ public function clearByNamespace($namespace) { + $namespace = (string) $namespace; + if ($namespace === '') { + throw new Exception\InvalidArgumentException('No namespace given'); + } + $options = $this->getOptions(); $prefix = $namespace . $options->getNamespaceSeparator(); @@ -182,8 +187,14 @@ public function clearByNamespace($namespace) */ public function clearByPrefix($prefix) { - $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator() . $prefix; + $prefix = (string) $prefix; + if ($prefix === '') { + throw new Exception\InvalidArgumentException('No prefix given'); + } + + $options = $this->getOptions(); + $namespace = $options->getNamespace(); + $prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator() . $prefix; xcache_unset_by_prefix($prefix); return true; @@ -217,18 +228,35 @@ public function flush() */ public function getIterator() { - $options = $this->getOptions(); - $prefixL = strlen($options->getNamespace() . $options->getNamespaceSeparator()); - $keys = array(); + + $options = $this->getOptions(); + $namespace = $options->getNamespace(); + $keys = array(); $this->initAdminAuth(); - $cnt = xcache_count(XC_TYPE_VAR); - for ($i=0; $i < $cnt; $i++) { - $list = xcache_list(XC_TYPE_VAR, $i); - foreach ($list['cache_list'] as & $item) { - $keys[] = substr($item['name'], $prefixL); + + if ($namespace === '') { + $cnt = xcache_count(XC_TYPE_VAR); + for ($i=0; $i < $cnt; $i++) { + $list = xcache_list(XC_TYPE_VAR, $i); + foreach ($list['cache_list'] as & $item) { + $keys[] = $item['name']; + } + } + } else { + + $prefix = $namespace . $options->getNamespaceSeparator(); + $prefixL = strlen($prefix); + + $cnt = xcache_count(XC_TYPE_VAR); + for ($i=0; $i < $cnt; $i++) { + $list = xcache_list(XC_TYPE_VAR, $i); + foreach ($list['cache_list'] as & $item) { + $keys[] = substr($item['name'], $prefixL); + } } } + $this->resetAdminAuth(); return new KeyListIterator($this, $keys); @@ -248,7 +276,8 @@ public function getIterator() protected function internalGetItem(& $normalizedKey, & $success = null, & $casToken = null) { $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); + $namespace = $options->getNamespace(); + $prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; $result = xcache_get($internalKey); @@ -270,8 +299,9 @@ protected function internalGetItem(& $normalizedKey, & $success = null, & $casTo */ protected function internalHasItem(& $normalizedKey) { - $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); + $options = $this->getOptions(); + $namespace = $options->getNamespace(); + $prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator(); return xcache_isset($prefix . $normalizedKey); } @@ -285,7 +315,8 @@ protected function internalHasItem(& $normalizedKey) protected function internalGetMetadata(& $normalizedKey) { $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); + $namespace = $options->getNamespace(); + $prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; if (xcache_isset($internalKey)) { @@ -320,7 +351,8 @@ protected function internalGetMetadata(& $normalizedKey) protected function internalSetItem(& $normalizedKey, & $value) { $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); + $namespace = $options->getNamespace(); + $prefix = ($options === '') ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; $ttl = $options->getTtl(); @@ -344,7 +376,8 @@ protected function internalSetItem(& $normalizedKey, & $value) protected function internalRemoveItem(& $normalizedKey) { $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); + $namespace = $options->getNamespace(); + $prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; return xcache_unset($internalKey); @@ -361,7 +394,8 @@ protected function internalRemoveItem(& $normalizedKey) protected function internalIncrementItem(& $normalizedKey, & $value) { $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); + $namespace = $options->getNamespace(); + $prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; $ttl = $options->getTtl(); $value = (int) $value; @@ -380,7 +414,8 @@ protected function internalIncrementItem(& $normalizedKey, & $value) protected function internalDecrementItem(& $normalizedKey, & $value) { $options = $this->getOptions(); - $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); + $namespace = $options->getNamespace(); + $prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; $ttl = $options->getTtl(); $value = (int) $value; From c8d1a54b38fd37b12790a0282184f058c7a8e035 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 5 Dec 2012 20:30:02 +0100 Subject: [PATCH 11/13] Remove the pattern cache factory --- src/Service/PatternCacheFactory.php | 35 ------------------ test/Service/PatternCacheFactoryTest.php | 46 ------------------------ 2 files changed, 81 deletions(-) delete mode 100644 src/Service/PatternCacheFactory.php delete mode 100644 test/Service/PatternCacheFactoryTest.php diff --git a/src/Service/PatternCacheFactory.php b/src/Service/PatternCacheFactory.php deleted file mode 100644 index 85ef02ef5..000000000 --- a/src/Service/PatternCacheFactory.php +++ /dev/null @@ -1,35 +0,0 @@ -get('Config'); - $cacheConfig = isset($config['cache_pattern']) ? $config['cache_pattern'] : array(); - $cache = PatternFactory::factory($cacheConfig); - - return $cache; - } -} diff --git a/test/Service/PatternCacheFactoryTest.php b/test/Service/PatternCacheFactoryTest.php deleted file mode 100644 index aaea53c47..000000000 --- a/test/Service/PatternCacheFactoryTest.php +++ /dev/null @@ -1,46 +0,0 @@ -sm = new ServiceManager(); - $this->sm->setService('Config', array('cache_pattern' => 'capture')); - $this->sm->setFactory('PatternCacheFactory', 'Zend\Cache\Service\PatternCacheFactory'); - } - - public function tearDown() - { - Cache\StorageFactory::resetAdapterPluginManager(); - Cache\StorageFactory::resetPluginManager(); - } - - public function testCreateServiceCache() - { - $cache = $this->sm->get('PatternCacheFactory'); - $this->assertEquals('Zend\Cache\Pattern\CaptureCache', get_class($cache)); - } -} From e60558c33e35f5af43513a56f728841b9943098c Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Thu, 13 Dec 2012 07:27:26 +0100 Subject: [PATCH 12/13] Cache: Added missing InvalidArgumentException on an empty argument on clearByPrefix of the session storage --- src/Storage/Adapter/Session.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Storage/Adapter/Session.php b/src/Storage/Adapter/Session.php index eebb34810..fc0d2487f 100644 --- a/src/Storage/Adapter/Session.php +++ b/src/Storage/Adapter/Session.php @@ -117,6 +117,11 @@ public function flush() */ public function clearByPrefix($prefix) { + $prefix = (string) $prefix; + if ($prefix === '') { + throw new Exception\InvalidArgumentException('No prefix given'); + } + $cntr = $this->getSessionContainer(); $ns = $this->getOptions()->getNamespace(); From f2a6fb6e99fe59c93be5dfb8fa7f503223bdbe9e Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Thu, 13 Dec 2012 07:31:08 +0100 Subject: [PATCH 13/13] Cache: fixed testGetTotalSpace to allow 0 byte as total space (if total space is unknown) --- test/Storage/Adapter/CommonAdapterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Storage/Adapter/CommonAdapterTest.php b/test/Storage/Adapter/CommonAdapterTest.php index 1b274c318..0e46955f5 100644 --- a/test/Storage/Adapter/CommonAdapterTest.php +++ b/test/Storage/Adapter/CommonAdapterTest.php @@ -1073,7 +1073,7 @@ public function testGetTotalSpace() } $totalSpace = $this->_storage->getTotalSpace(); - $this->assertGreaterThan(0, $totalSpace); + $this->assertGreaterThanOrEqual(0, $totalSpace); if ($this->_storage instanceof AvailableSpaceCapableInterface) { $availableSpace = $this->_storage->getAvailableSpace();