Skip to content

Commit dd0d878

Browse files
committed
Merge pull request #53 from php-cache/tagging04
Support for tagging 0.4
2 parents fffffa3 + 0f45b38 commit dd0d878

File tree

7 files changed

+54
-37
lines changed

7 files changed

+54
-37
lines changed

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"router",
1010
"session"
1111
],
12-
"homepage": "https://github.com/php-cache/cache-bundle",
12+
"homepage": "http://www.php-cache.com/en/latest/",
1313
"license": "MIT",
1414
"authors": [
1515
{
@@ -24,15 +24,15 @@
2424
}
2525
],
2626
"require": {
27-
"php": "^5.5|^7",
27+
"php": "^5.5|^7.0",
2828
"symfony/framework-bundle": "^2.7|^3.0",
29-
"cache/taggable-cache": "^0.3",
29+
"cache/taggable-cache": "^0.4",
3030
"cache/session-handler": "^0.1"
3131
},
3232
"require-dev": {
3333
"phpunit/phpunit": "^5.1|^4.0",
3434
"cache/psr-6-doctrine-bridge": "^2.0",
35-
"cache/array-adapter": "@stable"
35+
"cache/array-adapter": "^0.4"
3636
},
3737
"suggest": {
3838
"cache/adapter-bundle": "To register PSR-6 compliant cache implementations as services.",

src/Cache/FixedTaggingCachePool.php

+21-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Cache\CacheBundle\Cache;
1313

14+
use Cache\Taggable\TaggableItemInterface;
1415
use Cache\Taggable\TaggablePoolInterface;
1516
use Psr\Cache\CacheItemInterface;
1617
use Psr\Cache\CacheItemPoolInterface;
@@ -48,54 +49,56 @@ public function __construct(TaggablePoolInterface $cache, array $tags)
4849
*/
4950
public function getItem($key)
5051
{
51-
return $this->cache->getItem($key, $this->tags);
52+
return $this->cache->getItem($key);
5253
}
5354

5455
/**
5556
* {@inheritdoc}
5657
*/
5758
public function getItems(array $keys = [])
5859
{
59-
return $this->cache->getItems($keys, $this->tags);
60+
return $this->cache->getItems($keys);
6061
}
6162

6263
/**
6364
* {@inheritdoc}
6465
*/
6566
public function hasItem($key)
6667
{
67-
return $this->cache->hasItem($key, $this->tags);
68+
return $this->cache->hasItem($key);
6869
}
6970

7071
/**
7172
* {@inheritdoc}
7273
*/
7374
public function clear()
7475
{
75-
return $this->cache->clear($this->tags);
76+
return $this->cache->clear();
7677
}
7778

7879
/**
7980
* {@inheritdoc}
8081
*/
8182
public function deleteItem($key)
8283
{
83-
return $this->cache->deleteItem($key, $this->tags);
84+
return $this->cache->deleteItem($key);
8485
}
8586

8687
/**
8788
* {@inheritdoc}
8889
*/
8990
public function deleteItems(array $keys)
9091
{
91-
return $this->cache->deleteItems($keys, $this->tags);
92+
return $this->cache->deleteItems($keys);
9293
}
9394

9495
/**
9596
* {@inheritdoc}
9697
*/
9798
public function save(CacheItemInterface $item)
9899
{
100+
$this->addTags($item);
101+
99102
return $this->cache->save($item);
100103
}
101104

@@ -104,9 +107,21 @@ public function save(CacheItemInterface $item)
104107
*/
105108
public function saveDeferred(CacheItemInterface $item)
106109
{
110+
$this->addTags($item);
111+
107112
return $this->cache->saveDeferred($item);
108113
}
109114

115+
/**
116+
* @param TaggableItemInterface $item
117+
*/
118+
private function addTags(TaggableItemInterface $item)
119+
{
120+
foreach ($this->tags as $tag) {
121+
$item->addTag($tag);
122+
}
123+
}
124+
110125
/**
111126
* {@inheritdoc}
112127
*/

src/Cache/RecordingCachePool.php

+23-15
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ private function timeCall($name, array $arguments = null)
6767
return $object;
6868
}
6969

70-
public function getItem($key, array $tags = [])
70+
public function getItem($key)
7171
{
72-
$call = $this->timeCall(__FUNCTION__, [$key, $tags]);
73-
$result = $call->result;
74-
$call->isHit = $result->isHit();
72+
$call = $this->timeCall(__FUNCTION__, [$key]);
73+
$result = $call->result;
74+
$call->isHit = $result->isHit();
7575

7676
// Display the result in a good way depending on the data type
7777
if ($call->isHit) {
@@ -85,17 +85,17 @@ public function getItem($key, array $tags = [])
8585
return $result;
8686
}
8787

88-
public function hasItem($key, array $tags = [])
88+
public function hasItem($key)
8989
{
90-
$call = $this->timeCall(__FUNCTION__, [$key, $tags]);
90+
$call = $this->timeCall(__FUNCTION__, [$key]);
9191
$this->addCall($call);
9292

9393
return $call->result;
9494
}
9595

96-
public function deleteItem($key, array $tags = [])
96+
public function deleteItem($key)
9797
{
98-
$call = $this->timeCall(__FUNCTION__, [$key, $tags]);
98+
$call = $this->timeCall(__FUNCTION__, [$key]);
9999
$this->addCall($call);
100100

101101
return $call->result;
@@ -125,35 +125,43 @@ public function saveDeferred(CacheItemInterface $item)
125125
return $call->result;
126126
}
127127

128-
public function getItems(array $keys = [], array $tags = [])
128+
public function getItems(array $keys = [])
129129
{
130-
$call = $this->timeCall(__FUNCTION__, [$keys, $tags]);
130+
$call = $this->timeCall(__FUNCTION__, [$keys]);
131131
$result = $call->result;
132132
$call->result = sprintf('<DATA:%s>', gettype($result));
133133
$this->addCall($call);
134134

135135
return $result;
136136
}
137137

138-
public function clear(array $tags = [])
138+
public function clear()
139+
{
140+
$call = $this->timeCall(__FUNCTION__, []);
141+
$this->addCall($call);
142+
143+
return $call->result;
144+
}
145+
146+
public function clearTags(array $tags)
139147
{
140-
$call = $this->timeCall(__FUNCTION__, [$tags]);
148+
$call = $this->timeCall(__FUNCTION__, [$tags]);
141149
$this->addCall($call);
142150

143151
return $call->result;
144152
}
145153

146-
public function deleteItems(array $keys, array $tags = [])
154+
public function deleteItems(array $keys)
147155
{
148-
$call = $this->timeCall(__FUNCTION__, [$keys, $tags]);
156+
$call = $this->timeCall(__FUNCTION__, [$keys]);
149157
$this->addCall($call);
150158

151159
return $call->result;
152160
}
153161

154162
public function commit()
155163
{
156-
$call = $this->timeCall(__FUNCTION__);
164+
$call = $this->timeCall(__FUNCTION__);
157165
$this->addCall($call);
158166

159167
return $call->result;

src/Command/CacheFlushCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function clearTypedCacheFromService($type, $serviceId)
123123
/** @type \Psr\Cache\CacheItemPoolInterface $service */
124124
$service = $this->getContainer()->get($serviceId);
125125
if ($service instanceof TaggablePoolInterface) {
126-
return $service->clear([$type]);
126+
return $service->clearTags([$type]);
127127
} else {
128128
return $service->clear();
129129
}

src/Routing/CachingRouter.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Cache\CacheBundle\Routing;
1313

14-
use Cache\Taggable\TaggablePoolInterface;
14+
use Cache\Taggable\TaggableItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
1616
use Symfony\Component\Routing\RequestContext;
1717
use Symfony\Component\Routing\RouterInterface;
@@ -163,10 +163,10 @@ public function __call($method, $args)
163163
*/
164164
private function getCacheItemFromKey($key, $tag)
165165
{
166-
if ($this->cache instanceof TaggablePoolInterface) {
167-
$item = $this->cache->getItem($key, ['router', $tag]);
168-
} else {
169-
$item = $this->cache->getItem($key);
166+
$item = $this->cache->getItem($key);
167+
168+
if ($item instanceof TaggableItemInterface) {
169+
$item->setTags(['router', $tag]);
170170
}
171171

172172
return $item;

tests/ContainerTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
class ContainerTest extends TestCase
2020
{
21-
/**
22-
*
23-
*/
2421
public function testContainer()
2522
{
2623
//$container = $this->createContainer();

tests/DependencyInjection/CacheExtensionTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
*/
2121
class CacheExtensionTest extends TestCase
2222
{
23-
/**
24-
*
25-
*/
2623
public function testRouterBuilder()
2724
{
2825
$container = $this->createContainerFromFile('router');

0 commit comments

Comments
 (0)