From d17414dc0bfe40fda819d1f6fa52f385fb855451 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sun, 25 Oct 2015 21:26:09 +0100 Subject: [PATCH 1/3] fixed 'Undefined variable: key' with edge case in MongoDb::internalGetItem() --- src/Storage/Adapter/MongoDb.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Adapter/MongoDb.php b/src/Storage/Adapter/MongoDb.php index 8f15b545b..1cee92d11 100644 --- a/src/Storage/Adapter/MongoDb.php +++ b/src/Storage/Adapter/MongoDb.php @@ -135,7 +135,7 @@ protected function internalGetItem(& $normalizedKey, & $success = null, & $casTo } if ($result['expires']->sec < time()) { - $this->internalRemoveItem($key); + $this->internalRemoveItem($normalizedKey); return; } From c20124f36294df63a46d1b5b8727d94e35bd6553 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sun, 29 Nov 2015 15:30:01 +0100 Subject: [PATCH 2/3] fixed expiration support and removed duplicated tests of MongoDb adapter --- src/Storage/Adapter/MongoDb.php | 7 +----- test/Storage/Adapter/MongoDbTest.php | 33 ---------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/src/Storage/Adapter/MongoDb.php b/src/Storage/Adapter/MongoDb.php index 1cee92d11..88bb4cec0 100644 --- a/src/Storage/Adapter/MongoDb.php +++ b/src/Storage/Adapter/MongoDb.php @@ -136,7 +136,6 @@ protected function internalGetItem(& $normalizedKey, & $success = null, & $casTo if ($result['expires']->sec < time()) { $this->internalRemoveItem($normalizedKey); - return; } } @@ -241,12 +240,8 @@ protected function internalGetCapabilities() 'supportedMetadata' => [ '_id', ], - 'minTtl' => 0, - 'maxTtl' => 0, + 'minTtl' => 1, 'staticTtl' => true, - 'ttlPrecision' => 1, - 'useRequestTime' => false, - 'expiredRead' => false, 'maxKeyLength' => 255, 'namespaceIsPrefix' => true, ] diff --git a/test/Storage/Adapter/MongoDbTest.php b/test/Storage/Adapter/MongoDbTest.php index a1ccf04c8..59ef62a67 100644 --- a/test/Storage/Adapter/MongoDbTest.php +++ b/test/Storage/Adapter/MongoDbTest.php @@ -60,37 +60,4 @@ public function testSetOptionsNotMongoDbOptions() $this->assertInstanceOf('\Zend\Cache\Storage\Adapter\MongoDbOptions', $this->_storage->getOptions()); } - - public function testCachedItemsExpire() - { - $ttl = 2; - $key = 'foo'; - $value = 'bar'; - - $this->_storage->getOptions()->setTtl($ttl); - - $this->_storage->setItem($key, $value); - - // wait for the cached item to expire - sleep($ttl * 2); - - $this->assertNull($this->_storage->getItem($key)); - } - - public function testFlush() - { - $key1 = 'foo'; - $key2 = 'key'; - $value1 = 'bar'; - $value2 = 'value'; - - $this->assertEquals([], $this->_storage->setItems([ - $key1 => $value1, - $key2 => $value2, - ])); - - $this->assertTrue($this->_storage->flush()); - - $this->assertEquals([], $this->_storage->hasItems([$key1, $key2])); - } } From aac3a3085d68ef2d8c2b01fb1481d66adfb69e3c Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sun, 29 Nov 2015 15:58:52 +0100 Subject: [PATCH 3/3] Added hotfix for #25 to CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c54b4e4fb..c178f326f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed +- [#25](https://github.com/zendframework/zend-cache/pull/25) + MongoDd: fixed expiration support and removed duplicated tests - [#40](https://github.com/zendframework/zend-cache/pull/40) Fixed TTL support of `Redis::addItem` - [#18](https://github.com/zendframework/zend-cache/issues/18)