1212namespace Cache \Adapter \Common ;
1313
1414use Cache \Adapter \Common \Exception \InvalidArgumentException ;
15- use Cache \Taggable \TaggableItemInterface ;
16- use Cache \Taggable \TaggablePoolInterface ;
17- use Cache \Taggable \TaggablePoolTrait ;
1815use Psr \Cache \CacheItemInterface ;
1916use Psr \Cache \CacheItemPoolInterface ;
2017
2118/**
2219 * @author Aaron Scherer <[email protected] > 2320 * @author Tobias Nyholm <[email protected] > 2421 */
25- abstract class AbstractCachePool implements CacheItemPoolInterface, TaggablePoolInterface
22+ abstract class AbstractCachePool implements CacheItemPoolInterface
2623{
27- use TaggablePoolTrait;
28-
2924 /**
3025 * @type CacheItemInterface[] deferred
3126 */
3227 protected $ deferred = [];
3328
29+ /**
30+ * @param CacheItemInterface $item
31+ * @param int|null $ttl seconds from now
32+ *
33+ * @return bool true if saved
34+ */
35+ abstract protected function storeItemInCache (CacheItemInterface $ item , $ ttl );
36+
37+ /**
38+ * Fetch an object from the cache implementation.
39+ *
40+ * @param string $key
41+ *
42+ * @return array with [isHit, value]
43+ */
44+ abstract protected function fetchObjectFromCache ($ key );
45+
46+ /**
47+ * Clear all objects from cache.
48+ *
49+ * @return bool false if error
50+ */
51+ abstract protected function clearAllObjectsFromCache ();
52+
53+ /**
54+ * Remove one object from cache.
55+ *
56+ * @param string $key
57+ *
58+ * @return bool
59+ */
60+ abstract protected function clearOneObjectFromCache ($ key );
61+
3462 /**
3563 * Make sure to commit before we destruct.
3664 */
@@ -42,19 +70,9 @@ public function __destruct()
4270 /**
4371 * {@inheritdoc}
4472 */
45- public function getItem ($ key, array $ tags = [] )
73+ public function getItem ($ key )
4674 {
4775 $ this ->validateKey ($ key );
48- $ taggedKey = $ this ->generateCacheKey ($ key , $ tags );
49-
50- return $ this ->getItemWithoutGenerateCacheKey ($ taggedKey );
51- }
52-
53- /**
54- * {@inheritdoc}
55- */
56- protected function getItemWithoutGenerateCacheKey ($ key )
57- {
5876 if (isset ($ this ->deferred [$ key ])) {
5977 $ item = $ this ->deferred [$ key ];
6078
@@ -68,23 +86,14 @@ protected function getItemWithoutGenerateCacheKey($key)
6886 return new CacheItem ($ key , $ func );
6987 }
7088
71- /**
72- * Fetch an object from the cache implementation.
73- *
74- * @param string $key
75- *
76- * @return array with [isHit, value]
77- */
78- abstract protected function fetchObjectFromCache ($ key );
79-
8089 /**
8190 * {@inheritdoc}
8291 */
83- public function getItems (array $ keys = [], array $ tags = [] )
92+ public function getItems (array $ keys = [])
8493 {
8594 $ items = [];
8695 foreach ($ keys as $ key ) {
87- $ items [$ key ] = $ this ->getItem ($ key, $ tags );
96+ $ items [$ key ] = $ this ->getItem ($ key );
8897 }
8998
9099 return $ items ;
@@ -93,117 +102,71 @@ public function getItems(array $keys = [], array $tags = [])
93102 /**
94103 * {@inheritdoc}
95104 */
96- public function hasItem ($ key, array $ tags = [] )
105+ public function hasItem ($ key )
97106 {
98- return $ this ->getItem ($ key, $ tags )->isHit ();
107+ return $ this ->getItem ($ key )->isHit ();
99108 }
100109
101110 /**
102111 * {@inheritdoc}
103112 */
104- public function clear (array $ tags = [] )
113+ public function clear ()
105114 {
106- if (!empty ($ tags )) {
107- foreach ($ tags as $ tag ) {
108- $ this ->flushTag ($ tag );
109- }
110-
111- return true ;
112- }
113-
114115 // Clear the deferred items
115116 $ this ->deferred = [];
116117
117118 return $ this ->clearAllObjectsFromCache ();
118119 }
119120
120- /**
121- * Clear all objects from cache.
122- *
123- * @return bool false if error
124- */
125- abstract protected function clearAllObjectsFromCache ();
126-
127121 /**
128122 * {@inheritdoc}
129123 */
130- public function deleteItem ($ key, array $ tags = [] )
124+ public function deleteItem ($ key )
131125 {
132- return $ this ->deleteItems ([$ key ], $ tags );
126+ return $ this ->deleteItems ([$ key ]);
133127 }
134128
135129 /**
136130 * {@inheritdoc}
137131 */
138- public function deleteItems (array $ keys, array $ tags = [] )
132+ public function deleteItems (array $ keys )
139133 {
140134 $ deleted = true ;
141135 foreach ($ keys as $ key ) {
142136 $ this ->validateKey ($ key );
143- $ taggedKey = $ this ->generateCacheKey ($ key , $ tags );
144137
145138 // Delete form deferred
146- unset($ this ->deferred [$ taggedKey ]);
139+ unset($ this ->deferred [$ key ]);
147140
148- if (!$ this ->clearOneObjectFromCache ($ taggedKey )) {
141+ if (!$ this ->clearOneObjectFromCache ($ key )) {
149142 $ deleted = false ;
150143 }
151144 }
152145
153146 return $ deleted ;
154147 }
155148
156- /**
157- * Remove one object from cache.
158- *
159- * @param string $key
160- *
161- * @return bool
162- */
163- abstract protected function clearOneObjectFromCache ($ key );
164-
165149 /**
166150 * {@inheritdoc}
167151 */
168152 public function save (CacheItemInterface $ item )
169153 {
170- if ($ item instanceof TaggableItemInterface) {
171- $ key = $ item ->getTaggedKey ();
172- } else {
173- $ key = $ item ->getKey ();
174- }
175-
176154 $ timeToLive = null ;
177155 if ($ item instanceof HasExpirationDateInterface) {
178156 if (null !== $ expirationDate = $ item ->getExpirationDate ()) {
179157 $ timeToLive = $ expirationDate ->getTimestamp () - time ();
180158 }
181159 }
182160
183- return $ this ->storeItemInCache ($ key , $ item , $ timeToLive );
161+ return $ this ->storeItemInCache ($ item , $ timeToLive );
184162 }
185163
186- /**
187- * @param string $key
188- * @param CacheItemInterface $item
189- * @param int|null $ttl seconds from now
190- *
191- * @return bool true if saved
192- */
193- abstract protected function storeItemInCache ($ key , CacheItemInterface $ item , $ ttl );
194-
195164 /**
196165 * {@inheritdoc}
197166 */
198167 public function saveDeferred (CacheItemInterface $ item )
199168 {
200- if ($ item instanceof TaggableItemInterface) {
201- $ key = $ item ->getTaggedKey ();
202- } else {
203- $ key = $ item ->getKey ();
204- }
205-
206- $ this ->deferred [$ key ] = $ item ;
169+ $ this ->deferred [$ item ->getKey ()] = $ item ;
207170
208171 return true ;
209172 }
@@ -244,14 +207,4 @@ protected function validateKey($key)
244207 ));
245208 }
246209 }
247-
248- /**
249- * @param string $name
250- *
251- * @throws InvalidArgumentException
252- */
253- protected function validateTagName ($ name )
254- {
255- $ this ->validateKey ($ name );
256- }
257210}
0 commit comments