1111
1212namespace Cache \CacheBundle \Cache ;
1313
14- use Cache \Taggable \ TaggableItemInterface ;
15- use Cache \Taggable \ TaggablePoolInterface ;
14+ use Cache \TagInterop \ TaggableCacheItemInterface ;
15+ use Cache \TagInterop \ TaggableCacheItemPoolInterface ;
1616use Psr \Cache \CacheItemInterface ;
17- use Psr \Cache \CacheItemPoolInterface ;
17+ use Psr \Cache \InvalidArgumentException ;
1818
1919/**
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.
2221 *
2322 * @author Tobias Nyholm <[email protected] > 2423 */
25- class FixedTaggingCachePool implements CacheItemPoolInterface
24+ class FixedTaggingCachePool implements TaggableCacheItemPoolInterface
2625{
2726 /**
28- * @type CacheItemPoolInterface|TaggablePoolInterface
27+ * @type TaggableCacheItemPoolInterface
2928 */
3029 private $ cache ;
3130
@@ -35,10 +34,10 @@ class FixedTaggingCachePool implements CacheItemPoolInterface
3534 private $ tags ;
3635
3736 /**
38- * @param TaggablePoolInterface $cache
39- * @param array $tags
37+ * @param TaggableCacheItemPoolInterface $cache
38+ * @param array $tags
4039 */
41- public function __construct (TaggablePoolInterface $ cache , array $ tags )
40+ public function __construct (TaggableCacheItemPoolInterface $ cache , array $ tags )
4241 {
4342 $ this ->cache = $ cache ;
4443 $ this ->tags = $ tags ;
@@ -97,10 +96,12 @@ public function deleteItems(array $keys)
9796 */
9897 public function save (CacheItemInterface $ item )
9998 {
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. ' );
102101 }
103102
103+ $ item ->setTags ($ this ->tags );
104+
104105 return $ this ->cache ->save ($ item );
105106 }
106107
@@ -109,26 +110,36 @@ public function save(CacheItemInterface $item)
109110 */
110111 public function saveDeferred (CacheItemInterface $ item )
111112 {
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 );
113118
114119 return $ this ->cache ->saveDeferred ($ item );
115120 }
116121
117122 /**
118- * @param TaggableItemInterface $item
123+ * {@inheritdoc}
119124 */
120- private function addTags ( TaggableItemInterface $ item )
125+ public function commit ( )
121126 {
122- foreach ($ this ->tags as $ tag ) {
123- $ item ->addTag ($ tag );
124- }
127+ return $ this ->cache ->commit ();
125128 }
126129
127130 /**
128131 * {@inheritdoc}
129132 */
130- public function commit ( )
133+ public function invalidateTag ( $ tag )
131134 {
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 );
133144 }
134145}
0 commit comments