Implemented PruneableInterface on TagAwareAdapter
This commit is contained in:
parent
61966df131
commit
b635b62463
@ -14,11 +14,12 @@ namespace Symfony\Component\Cache\Adapter;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Symfony\Component\Cache\CacheItem;
|
||||
use Symfony\Component\Cache\PruneableInterface;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class TagAwareAdapter implements TagAwareAdapterInterface
|
||||
class TagAwareAdapter implements TagAwareAdapterInterface, PruneableInterface
|
||||
{
|
||||
const TAGS_PREFIX = "\0tags\0";
|
||||
|
||||
@ -334,4 +335,16 @@ class TagAwareAdapter implements TagAwareAdapterInterface
|
||||
|
||||
return $tagVersions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prune()
|
||||
{
|
||||
if ($this->itemsAdapter instanceof PruneableInterface) {
|
||||
return $this->itemsAdapter->prune();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ CHANGELOG
|
||||
-----
|
||||
|
||||
* added PruneableInterface so PSR-6 or PSR-16 cache implementations can declare support for manual stale cache pruning
|
||||
* added prune logic to FilesystemTrait, PhpFilesTrait, PdoTrait, and ChainTrait
|
||||
* added prune logic to FilesystemTrait, PhpFilesTrait, PdoTrait, TagAwareAdapter and ChainTrait
|
||||
* now FilesystemAdapter, PhpFilesAdapter, FilesystemCache, PhpFilesCache, PdoAdapter, PdoCache, ChainAdapter, and
|
||||
ChainCache implement PruneableInterface and support manual stale cache pruning
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Cache\Tests\Adapter;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
|
||||
@ -125,4 +126,60 @@ class TagAwareAdapterTest extends AdapterTestCase
|
||||
$i = $pool->getItem('k');
|
||||
$this->assertSame(array('foo' => 'foo'), $i->getPreviousTags());
|
||||
}
|
||||
|
||||
public function testPrune()
|
||||
{
|
||||
$cache = new TagAwareAdapter($this->getPruneableMock());
|
||||
$this->assertTrue($cache->prune());
|
||||
|
||||
$cache = new TagAwareAdapter($this->getNonPruneableMock());
|
||||
$this->assertFalse($cache->prune());
|
||||
|
||||
$cache = new TagAwareAdapter($this->getFailingPruneableMock());
|
||||
$this->assertFalse($cache->prune());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface
|
||||
*/
|
||||
private function getFailingPruneableMock()
|
||||
{
|
||||
$pruneable = $this
|
||||
->getMockBuilder(PruneableCacheInterface::class)
|
||||
->getMock();
|
||||
|
||||
$pruneable
|
||||
->expects($this->atLeastOnce())
|
||||
->method('prune')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
return $pruneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|AdapterInterface
|
||||
*/
|
||||
private function getNonPruneableMock()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder(AdapterInterface::class)
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user