Merge branch '4.1'

* 4.1:
  [Cache] Fix exception handling in AbstractTrait::clear()
  Revert "minor #27649 [Cache] fix Memcached tests (nicolas-grekas)"
This commit is contained in:
Nicolas Grekas 2018-06-20 11:26:44 +02:00
commit 683bbf9eaf
5 changed files with 24 additions and 52 deletions

View File

@ -22,7 +22,6 @@ class MemcachedAdapterTest extends AdapterTestCase
);
protected static $client;
protected static $enableVersioning = false;
public static function setupBeforeClass()
{
@ -42,23 +41,7 @@ class MemcachedAdapterTest extends AdapterTestCase
{
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;
$adapter = new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
if (self::$enableVersioning) {
$adapter->enableVersioning();
}
return $adapter;
}
public function testClear()
{
self::$enableVersioning = true;
try {
parent::testClear();
} finally {
self::$enableVersioning = false;
}
return new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
}
public function testOptions()

View File

@ -38,6 +38,7 @@ abstract class CacheTestCase extends SimpleCacheTest
}
$cache = $this->createSimpleCache(2);
$cache->clear();
$cache->set('key.dlt', 'value');
sleep(1);
@ -46,6 +47,8 @@ abstract class CacheTestCase extends SimpleCacheTest
sleep(2);
$this->assertNull($cache->get('key.dlt'));
$cache->clear();
}
public function testNotUnserializable()
@ -55,6 +58,7 @@ abstract class CacheTestCase extends SimpleCacheTest
}
$cache = $this->createSimpleCache();
$cache->clear();
$cache->set('foo', new NotUnserializable());
@ -65,6 +69,8 @@ abstract class CacheTestCase extends SimpleCacheTest
foreach ($cache->getMultiple(array('foo')) as $value) {
}
$this->assertNull($value);
$cache->clear();
}
public function testPrune()
@ -79,6 +85,7 @@ abstract class CacheTestCase extends SimpleCacheTest
/** @var PruneableInterface|CacheInterface $cache */
$cache = $this->createSimpleCache();
$cache->clear();
$cache->set('foo', 'foo-val', new \DateInterval('PT05S'));
$cache->set('bar', 'bar-val', new \DateInterval('PT10S'));
@ -120,6 +127,8 @@ abstract class CacheTestCase extends SimpleCacheTest
$cache->prune();
$this->assertFalse($this->isPruned($cache, 'foo'));
$this->assertTrue($this->isPruned($cache, 'qux'));
$cache->clear();
}
}

View File

@ -23,7 +23,6 @@ class MemcachedCacheTest extends CacheTestCase
);
protected static $client;
protected static $enableVersioning = false;
public static function setupBeforeClass()
{
@ -43,23 +42,7 @@ class MemcachedCacheTest extends CacheTestCase
{
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false)) : self::$client;
$adapter = new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
if (self::$enableVersioning) {
$adapter->enableVersioning();
}
return $adapter;
}
public function testClear()
{
self::$enableVersioning = true;
try {
parent::testClear();
} finally {
self::$enableVersioning = false;
}
return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
}
public function testCreatePersistentConnectionShouldNotDupServerList()

View File

@ -20,12 +20,6 @@ class MemcachedCacheTextModeTest extends MemcachedCacheTest
{
$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false));
$adapter = new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
if (self::$enableVersioning) {
$adapter->enableVersioning();
}
return $adapter;
return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
}
}

View File

@ -105,17 +105,20 @@ trait AbstractTrait
*/
public function clear()
{
if ($cleared = $this->versioningIsEnabled) {
$this->namespaceVersion = 2;
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
$this->namespaceVersion = 1 + (int) $v;
}
$this->namespaceVersion .= ':';
$cleared = $this->doSave(array('@'.$this->namespace => $this->namespaceVersion), 0);
}
$this->deferred = array();
try {
if ($cleared = $this->versioningIsEnabled) {
$namespaceVersion = 2;
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
$namespaceVersion = 1 + (int) $v;
}
$namespaceVersion .= ':';
$cleared = $this->doSave(array('@'.$this->namespace => $namespaceVersion), 0);
if ($cleared = true === $cleared || array() === $cleared) {
$this->namespaceVersion = $namespaceVersion;
}
}
return $this->doClear($this->namespace) || $cleared;
} catch (\Exception $e) {
CacheItem::log($this->logger, 'Failed to clear the cache', array('exception' => $e));