8000 [Cache] Fix >30 days expirations with Memcached by nicolas-grekas · Pull Request #23970 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ public function testDefaultLifeTime()
$this->assertFalse($item->isHit());
}

public function testExpiration()
{
if (isset($this->skippedTests[__FUNCTION__])) {
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
}

$cache = $this->createCachePool();
$cache->save($cache->getItem('k1')->set('v1')->expiresAfter(2));
$cache->save($cache->getItem('k2')->set('v2')->expiresAfter(366 * 86400));

sleep(3);
$item = $cache->getItem('k1');
$this->assertFalse($item->isHit());
$this->assertNull($item->get(), "Item's value must be null when isHit() is false.");

$item = $cache->getItem('k2');
$this->assertTrue($item->isHit());
$this->assertSame('v2', $item->get());
}

public function testNotUnserializable()
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
class MemcachedAdapterTest extends AdapterTestCase
{
protected $skippedTests = array(
'testExpiration' => 'Testing expiration slows down the test suite',
'testHasItemReturnsFalseWhenDeferredItemIsExpired' => 'Testing expiration slows down the test suite',
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
);
Expand Down
4 changes: 4 addit 83BA ions & 0 deletions src/Symfony/Component/Cache/Traits/MemcachedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public static function createConnection($servers, array $options = array())
*/
protected function doSave(array $values, $lifetime)
{
if ($lifetime && $lifetime > 30 * 86400) {
$lifetime += time();
}

return $this->checkResultCode($this->client->setMulti($values, $lifetime));
}

Expand Down
0