10000 Merge branch '3.4' into 4.0 · symfony/symfony@6d26d9a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d26d9a

Browse files
Merge branch '3.4' into 4.0
* 3.4: [Cache] Fix exception handling in AbstractTrait::clear() Revert "minor #27649 [Cache] fix Memcached tests (nicolas-grekas)"
2 parents 9b64e8b + bef15ce commit 6d26d9a

File tree

5 files changed

+24
-52
lines changed

5 files changed

+24
-52
lines changed

src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class MemcachedAdapterTest extends AdapterTestCase
2222
);
2323

2424
protected static $client;
25-
protected static $enableVersioning = false;
2625

2726
public static function setupBeforeClass()
2827
{
@@ -42,23 +41,7 @@ public function createCachePool($defaultLifetime = 0)
4241
{
4342
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;
4443

45-
$adapter = new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
46-
47-
if (self::$enableVersioning) {
48-
$adapter->enableVersioning();
49-
}
50-
51-
return $adapter;
52-
}
53-
54-
public function testClear()
55-
{
56-
self::$enableVersioning = true;
57-
try {
58-
parent::testClear();
59-
} finally {
60-
self::$enableVersioning = false;
61-
}
44+
return new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
6245
}
6346

6447
public function testOptions()

src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function testDefaultLifeTime()
3838
}
3939

4040
$cache = $this->createSimpleCache(2);
41+
$cache->clear();
4142

4243
$cache->set('key.dlt', 'value');
4344
sleep(1);
@@ -46,6 +47,8 @@ public function testDefaultLifeTime()
4647

4748
sleep(2);
4849
$this->assertNull($cache->get('key.dlt'));
50+
51+
$cache->clear();
4952
}
5053

5154
public function testNotUnserializable()
@@ -55,6 +58,7 @@ public function testNotUnserializable()
5558
}
5659

5760
$cache = $this->createSimpleCache();
61+
$cache->clear();
5862

5963
$cache->set('foo', new NotUnserializable());
6064

@@ -65,6 +69,8 @@ public function testNotUnserializable()
6569
foreach ($cache->getMultiple(array('foo')) as $value) {
6670
}
6771
$this->assertNull($value);
72+
73+
$cache->clear();
6874
}
6975

7076
public function testPrune()
@@ -79,6 +85,7 @@ public function testPrune()
7985

8086
/** @var PruneableInterface|CacheInterface $cache */
8187
$cache = $this->createSimpleCache();
88+
$cache->clear();
8289

8390
$cache->set('foo', 'foo-val', new \DateInterval('PT05S'));
8491
$cache->set('bar', 'bar-val', new \DateInterval('PT10S'));
@@ -120,6 +127,8 @@ public function testPrune()
120127
$cache->prune();
121128
$this->assertFalse($this->isPruned($cache, 'foo'));
122129
$this->assertTrue($this->isPruned($cache, 'qux'));
130+
131+
$cache->clear();
123132
}
124133
}
125134

src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class MemcachedCacheTest extends CacheTestCase
2323
);
2424

2525
protected static $client;
26-
protected static $enableVersioning = false;
2726

2827
public static function setupBeforeClass()
2928
{
@@ -43,23 +42,7 @@ public function createSimpleCache($defaultLifetime = 0)
4342
{
4443
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false)) : self::$client;
4544

46-
$adapter = new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
47-
48-
if (self::$enableVersioning) {
49-
$adapter->enableVersioning();
50-
}
51-
52-
return $adapter;
53-
}
54-
55-
public function testClear()
56-
{
57-
self::$enableVersioning = true;
58-
try {
59-
parent::testClear();
60-
} finally {
61-
self::$enableVersioning = false;
62-
}
45+
return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
6346
}
6447

6548
public function testCreatePersistentConnectionShouldNotDupServerList()

src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTextModeTest.php

Lines changed: 1 addition & 7 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ public function createSimpleCache($defaultLifetime = 0)
2020
{
2121
$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false));
2222

23-
$adapter = new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
24-
25-
if (self::$enableVersioning) {
26-
$adapter->enableVersioning();
27-
}
28-
29-
return $adapter;
23+
return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
3024
}
3125
}

src/Symfony/Component/Cache/Traits/AbstractTrait.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,20 @@ public function hasItem($key)
104104
*/
105105
public function clear()
106106
{
107-
if ($cleared = $this->versioningIsEnabled) {
108-
$this->namespaceVersion = 2;
109-
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
110-
$this->namespaceVersion = 1 + (int) $v;
111-
}
112-
$this->namespaceVersion .= ':';
113-
$cleared = $this->doSave(array('@'.$this->namespace => $this->namespaceVersion), 0);
114-
}
115107
$this->deferred = array();
116-
117108
try {
109+
if ($cleared = $this->versioningIsEnabled) {
110+
$namespaceVersion = 2;
111+
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
112+
$namespaceVersion = 1 + (int) $v;
113+
}
114+
$namespaceVersion .= ':';
115+
$cleared = $this->doSave(array('@'.$this->namespace => $namespaceVersion), 0);
116+
if ($cleared = true === $cleared || array() === $cleared) {
117+
$this->namespaceVersion = $namespaceVersion;
118+
}
119+
}
120+
118121
return $this->doClear($this->namespace) || $cleared;
119122
} catch (\Exception $e) {
120123
CacheItem::log($this->logger, 'Failed to clear the cache', array('exception' => $e));

0 commit comments

Comments
 (0)
0