8000 bug #23970 [Cache] Fix >30 days expirations with Memcached (nicolas-g… · symfony/symfony@9db03c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9db03c1

Browse files
committed
bug #23970 [Cache] Fix >30 days expirations with Memcached (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [Cache] Fix >30 days expirations with Memcached | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - As documented in https://github.com/memcached/memcached/wiki/Programming#expiration, expiration times > 30 days are considered as unix timestamps by Memcached. Commits ------- 2348d64 [Cache] Fix >30 days expirations with Memcached
2 parents 7ce0665 + 2348d64 commit 9db03c1

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ public function testDefaultLifeTime()
4545
$this->assertFalse($item->isHit());
4646
}
4747

48+
public function testExpiration()
49+
{
50+
if (isset($this->skippedTests[__FUNCTION__])) {
51+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
52+
}
53+
54+
$cache = $this->createCachePool();
55+
$cache->save($cache->getItem('k1')->set('v1')->expiresAfter(2));
56+
$cache->save($cache->getItem('k2')->set('v2')->expiresAfter(366 * 86400));
57+
58+
sleep(3);
59+
$item = $cache->getItem('k1');
60+
$this->assertFalse($item->isHit());
61+
$this->assertNull($item->get(), "Item's value must be null when isHit() is false.");
62+
63+
$item = $cache->getItem('k2');
64+
$this->assertTrue($item->isHit());
65+
< 8000 span class=pl-c1>$this->assertSame('v2', $item->get());
66+
}
67+
4868
public function testNotUnserializable()
4969
{
5070
if (isset($this->skippedTests[__FUNCTION__])) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
class MemcachedAdapterTest extends AdapterTestCase
1818
{
1919
protected $skippedTests = array(
20-
'testExpiration' => 'Testing expiration slows down the test suite',
2120
'testHasItemReturnsFalseWhenDeferredItemIsExpired' => 'Testing expiration slows down the test suite',
2221
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
2322
);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ public static function createConnection($servers, array $options = array())
187187
*/
188188
protected function doSave(array $values, $lifetime)
189189
{
190+
if ($lifetime && $lifetime > 30 * 86400) {
191+
$lifetime += time();
192+
}
193+
190194
return $this->checkResultCode($this->client->setMulti($values, $lifetime));
191195
}
192196

0 commit comments

Comments
 (0)
0