8000 Default lifetime issue by ecanovas · Pull Request #1 · symfony/cache · GitHub
[go: up one dir, main page]

Skip to content

Default lifetime issue #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
3 changes: 3 additions & 0 deletions Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function ($key, $value, $isHit) use ($defaultLifetime) {
$item->value = $value;
$item->isHit = $isHit;
$item->defaultLifetime = $defaultLifetime;

if ($defaultLifetime>0)
$item->expiry = time() + $defaultLifetime;

return $item;
},
Expand Down
3 changes: 3 additions & 0 deletions Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function ($key, $value, $isHit) use ($defaultLifetime) {
$item->value = $value;
$item->isHit = $isHit;
$item->defaultLifetime = $defaultLifetime;

if ($defaultLifetime>0)
$item->expiry = time() + $defaultLifetime;

return $item;
},
Expand Down
58 changes: 58 additions & 0 deletions Tests/Adapter/ApcuAdapterDefaultTimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Ernesto Cánovas <ernesto.canovas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Cache\Tests\Adapter;

use Cache\IntegrationTests\CachePoolTest;
use Symfony\Component\Cache\Adapter\ApcuAdapter;


class ApcuAdapterDefaultTimeTest extends CachePoolTest
{
public function createCachePool()
{
if (defined('HHVM_VERSION')) {
$this->skippedTests['testDeferredSaveWithoutCommit'] = 'Fails on HHVM';
}

if (!function_exists('apcu_fetch') || !ini_get('apc.enabled') || ('cli' === PHP_SAPI && !ini_get('apc.enable_cli'))) {
$this->markTestSkipped('APCu extension is required.');
}
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Fails transiently on Windows.');
}

return new ApcuAdapter(str_replace('\\', '.', __CLASS__),5);
}

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

return;
}

$this->cache = $this->createCachePool();

$item = $this->cache->getItem('key.dlt');
$item->set('value');
$this->cache->save($item);
sleep(2);

$item = $this->cache->getItem('key.dlt');
$this->assertTrue($item->isHit());

sleep(6);
$item2 = $this->cache->getItem('key.dlt');
$this->assertFalse($item2->isHit());
}
}
49 changes: 49 additions & 0 deletions Tests/Adapter/ArrayAdapterDefaultTimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Ernesto Cánovas <ernesto.canovas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Cache\Tests\Adapter;

use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Tests\Adapter\ArrayAdapterTest;

class ArrayAdapterDefaultTimeTest extends ArrayAdapterTest
{

public function createCachePool()
{
return new ArrayAdapter(5);
}

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

return;
}

$this->cache = $this->createCachePool();

$item = $this->cache->getItem('key.dlt');
$item->set('value');
$this->cache->save($item);
sleep(2);

$item = $this->cache->getItem('key.dlt');
$this->assertTrue($item->isHit());

sleep(6);
$item2 = $this->cache->getItem('key.dlt');
$this->assertFalse($item2->isHit());
}


}
50 changes: 50 additions & 0 deletions Tests/Adapter/FilesystemAdapterDefaultTimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Ernesto Cánovas <ernesto.canovas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Cache\Tests\Adapter;

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Tests\Adapter\FilesystemAdapterTest;

class FilesystemAdapterDefaultTimeTest extends FilesystemAdapterTest
{

public function createCachePool()
{
if (defined('HHVM_VERSION')) {
$this->skippedTests['testDeferredSaveWithoutCommit'] = 'Fails on HHVM';
}
return new FilesystemAdapter('sf-cache',5);
}

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

return;
}

$this->cache = $this->createCachePool();

$item = $this->cache->getItem('key.dlt');
$item->set('value');
$this->cache->save($item);
sleep(2);

$item = $this->cache->getItem('key.dlt');
$this->assertTrue($item->isHit());

sleep(6);
$item2 = $this->cache->getItem('key.dlt');
$this->assertFalse($item2->isHit());
}
}
0