Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/167-memcached-return-when-no-entry-found' into d…
Browse files Browse the repository at this point in the history
…evelop

Forward port #167
Forward port #166
  • Loading branch information
weierophinney committed Apr 26, 2018
2 parents 147c65c + 6463865 commit aa20c3b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#165](https://github.com/zendframework/zend-cache/issues/165) fixes an issue
with the memcached adapter ensuring that retrieval returns boolean false when
unable to retrieve the requested item.

## 2.8.0 - 2018-04-24

Expand Down
4 changes: 2 additions & 2 deletions src/Storage/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ protected function internalGetItem(& $normalizedKey, & $success = null, & $casTo
if (func_num_args() > 2) {
if (defined('Memcached::GET_EXTENDED')) {
$output = $memc->get($internalKey, null, \Memcached::GET_EXTENDED);
$casToken = $output['cas'];
$result = $output['value'];
$casToken = $output ? $output['cas'] : $casToken;
$result = $output ? $output['value'] : false;
} else {
$result = $memc->get($internalKey, null, $casToken);
}
Expand Down
34 changes: 34 additions & 0 deletions test/Storage/Adapter/MemcachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Cache\Storage\Adapter;

use Prophecy\Argument;
use Zend\Cache;

/**
Expand Down Expand Up @@ -86,6 +87,39 @@ public function testOptionsAddServer()
$this->assertEquals($memcached->getOptions()->getServers(), $servers);
}

public function testMemcachedReturnsSuccessFalseOnError()
{
if (! defined('Memcached::GET_EXTENDED')) {
$this->markTestSkipped('Test skipped because Memcached < 3.0 with Memcached::GET_EXTENDED not defined');
return;
}

$resource = $this->prophesize(\Memcached::class);
$resourceManager = $this->prophesize(Cache\Storage\Adapter\MemcachedResourceManager::class);

$resourceManager->getResource(Argument::any())->willReturn($resource->reveal());
$resource->get(Argument::cetera())->willReturn(null);
$resource->getResultCode()->willReturn(\Memcached::RES_PARTIAL_READ);
$resource->getResultMessage()->willReturn('foo');

$storage = new Cache\Storage\Adapter\Memcached([
'resource_manager' => $resourceManager->reveal(),
]);

$storage->getEventManager()->attach(
'getItem.exception',
function (Cache\Storage\ExceptionEvent $e) {
$e->setThrowException(false);
$e->stopPropagation(true);
},
-1
);

$this->assertNull($storage->getItem('unknwon', $success, $casToken));
$this->assertFalse($success);
$this->assertNull($casToken);
}

public function getServersDefinitions()
{
$expectedServers = [
Expand Down

0 comments on commit aa20c3b

Please sign in to comment.