Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b635b62

Browse files
Toflarnicolas-grekas
authored andcommitted
Implemented PruneableInterface on TagAwareAdapter
1 parent 61966df commit b635b62

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\InvalidArgumentException;
1616
use Symfony\Component\Cache\CacheItem;
17+
use Symfony\Component\Cache\PruneableInterface;
1718

1819
/**
1920
* @author Nicolas Grekas <[email protected]>
2021
*/
21-
class TagAwareAdapter implements TagAwareAdapterInterface
22+
class TagAwareAdapter implements TagAwareAdapterInterface, PruneableInterface
2223
{
2324
const TAGS_PREFIX = "\0tags\0";
2425

@@ -334,4 +335,16 @@ private function getTagVersions(array $tagsByKey)
334335

335336
return $tagVersions;
336337
}
338+
339+
/**
340+
* {@inheritdoc}
341+
*/
342+
public function prune()
343+
{
344+
if ($this->itemsAdapter instanceof PruneableInterface) {
345+
return $this->itemsAdapter->prune();
346+
}
347+
348+
return false;
349+
}
337350
}

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CHANGELOG
55
-----
66

77
* added PruneableInterface so PSR-6 or PSR-16 cache implementations can declare support for manual stale cache pruning
8-
* added prune logic to FilesystemTrait, PhpFilesTrait, PdoTrait, and ChainTrait
8+
* added prune logic to FilesystemTrait, PhpFilesTrait, PdoTrait, TagAwareAdapter and ChainTrait
99
* now FilesystemAdapter, PhpFilesAdapter, FilesystemCache, PhpFilesCache, PdoAdapter, PdoCache, ChainAdapter, and
1010
ChainCache implement PruneableInterface and support manual stale cache pruning
1111

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use Symfony\Component\Cache\Adapter\AdapterInterface;
1415
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1516
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
1617

@@ -125,4 +126,60 @@ public function testGetPreviousTags()
125126
$i = $pool->getItem('k');
126127
$this->assertSame(array('foo' => 'foo'), $i->getPreviousTags());
127128
}
129+
130+
public function testPrune()
131+
{
132+
$cache = new TagAwareAdapter($this->getPruneableMock());
133+
$this->assertTrue($cache->prune());
134+
135+
$cache = new TagAwareAdapter($this->getNonPruneableMock());
136+
$this->assertFalse($cache->prune());
137+
138+
$cache = new TagAwareAdapter($this->getFailingPruneableMock());
139+
$this->assertFalse($cache->prune());
140+
}
141+
142+
/**
143+
* @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface
144+
*/
145+
private function getPruneableMock()
146+
{
147+
$pruneable = $this
148+
->getMockBuilder(PruneableCacheInterface::class)
149+
->getMock();
150+
151+
$pruneable
152+
->expects($this->atLeastOnce())
153+
->method('prune')
154+
->will($this->returnValue(true));
155+
156+
return $pruneable;
157+
}
158+
159+
/**
160+
* @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface
161+
*/
162+
private function getFailingPruneableMock()
163+
{
164+
$pruneable = $this
165+
->getMockBuilder(PruneableCacheInterface::class)
166+
->getMock();
167+
168+
$pruneable
169+
->expects($this->atLeastOnce())
170+
->method('prune')
171+
->will($this->returnValue(false));
172+
173+
return $pruneable;
174+
}
175+
176+
/**
177+
* @return \PHPUnit_Framework_MockObject_MockObject|AdapterInterface
178+
*/
179+
private function getNonPruneableMock()
180+
{
181+
return $this
182+
->getMockBuilder(AdapterInterface::class)
183+
->getMock();
184+
}
128185
}

0 commit comments

Comments
 (0)