11
11
12
12
namespace Cache \CacheBundle \Cache ;
13
13
14
- use Cache \Taggable \ TaggableItemInterface ;
15
- use Cache \Taggable \ TaggablePoolInterface ;
14
+ use Cache \TagInterop \ TaggableCacheItemInterface ;
15
+ use Cache \TagInterop \ TaggableCacheItemPoolInterface ;
16
16
use Psr \Cache \CacheItemInterface ;
17
- use Psr \Cache \CacheItemPoolInterface ;
17
+ use Psr \Cache \InvalidArgumentException ;
18
18
19
19
/**
20
- * This class is a decorator for a TaggablePoolInterface. It tags everything with predefined tags.
21
- * Use this class with the DoctrineBridge.
20
+ * This class is a decorator for a TaggableCacheItemPoolInterface. It tags everything with predefined tags.
22
21
*
23
22
* @author Tobias Nyholm <[email protected] >
24
23
*/
25
- class FixedTaggingCachePool implements CacheItemPoolInterface
24
+ class FixedTaggingCachePool implements TaggableCacheItemPoolInterface
26
25
{
27
26
/**
28
- * @type CacheItemPoolInterface|TaggablePoolInterface
27
+ * @type TaggableCacheItemPoolInterface
29
28
*/
30
29
private $ cache ;
31
30
@@ -35,10 +34,10 @@ class FixedTaggingCachePool implements CacheItemPoolInterface
35
34
private $ tags ;
36
35
37
36
/**
38
- * @param TaggablePoolInterface $cache
39
- * @param array $tags
37
+ * @param TaggableCacheItemPoolInterface $cache
38
+ * @param array $tags
40
39
*/
41
- public function __construct (TaggablePoolInterface $ cache , array $ tags )
40
+ public function __construct (TaggableCacheItemPoolInterface $ cache , array $ tags )
42
41
{
43
42
$ this ->cache = $ cache ;
44
43
$ this ->tags = $ tags ;
@@ -97,10 +96,12 @@ public function deleteItems(array $keys)
97
96
*/
98
97
public function save (CacheItemInterface $ item )
99
98
{
100
- if ($ item instanceof TaggableItemInterface ) {
101
- $ this -> addTags ( $ item );
99
+ if (! $ item instanceof TaggableCacheItemInterface ) {
100
+ throw new InvalidArgumentException ( ' Cache items are not transferable between pools. Item MUST implement TaggableCacheItemInterface. ' );
102
101
}
103
102
103
+ $ item ->setTags ($ this ->tags );
104
+
104
105
return $ this ->cache ->save ($ item );
105
106
}
106
107
@@ -109,26 +110,36 @@ public function save(CacheItemInterface $item)
109
110
*/
110
111
public function saveDeferred (CacheItemInterface $ item )
111
112
{
112
- $ this ->addTags ($ item );
113
+ if (!$ item instanceof TaggableCacheItemInterface) {
114
+ throw new InvalidArgumentException ('Cache items are not transferable between pools. Item MUST implement TaggableCacheItemInterface. ' );
115
+ }
116
+
117
+ $ item ->setTags ($ this ->tags );
113
118
114
119
return $ this ->cache ->saveDeferred ($ item );
115
120
}
116
121
117
122
/**
118
- * @param TaggableItemInterface $item
123
+ * {@inheritdoc}
119
124
*/
120
- private function addTags ( TaggableItemInterface $ item )
125
+ public function commit ( )
121
126
{
122
- foreach ($ this ->tags as $ tag ) {
123
- $ item ->addTag ($ tag );
124
- }
127
+ return $ this ->cache ->commit ();
125
128
}
126
129
127
130
/**
128
131
* {@inheritdoc}
129
132
*/
130
- public function commit ( )
133
+ public function invalidateTag ( $ tag )
131
134
{
132
- return $ this ->cache ->commit ();
135
+ return $ this ->invalidateTag ($ tag );
136
+ }
137
+
138
+ /**
139
+ * {@inheritdoc}
140
+ */
141
+ public function invalidateTags (array $ tags )
142
+ {
143
+ return $ this ->cache - $ this ->invalidateTags ($ tags );
133
144
}
134
145
}
0 commit comments