1111
1212namespace Cache \CacheBundle \Cache ;
1313
14+ use Cache \Taggable \TaggablePoolInterface ;
1415use Psr \Cache \CacheItemInterface ;
1516use Psr \Cache \CacheItemPoolInterface ;
1617
1718/**
1819 * @author Aaron Scherer <[email protected] > 1920 */
20- class LoggingCachePool implements CacheItemPoolInterface
21+ class LoggingCachePool implements CacheItemPoolInterface, TaggablePoolInterface
2122{
2223 /**
2324 * @type array
@@ -39,28 +40,50 @@ public function __construct(CacheItemPoolInterface $cachePool)
3940 $ this ->cachePool = $ cachePool ;
4041 }
4142
42- public function getItem ($ key )
43+ /**
44+ * @param string $name
45+ * @param array $arguments
46+ *
47+ * @return object
48+ */
49+ private function timeCall ($ name , array $ arguments = null )
4350 {
44- $ call = $ this ->timeCall (__FUNCTION__ , [$ key ]);
51+ $ start = microtime (true );
52+ $ result = call_user_func_array ([$ this ->cachePool , $ name ], $ arguments );
53+ $ time = microtime (true ) - $ start ;
54+
55+ $ object = (object ) compact ('name ' , 'arguments ' , 'start ' , 'time ' , 'result ' );
56+
57+ return $ object ;
58+ }
59+
60+ public function getItem ($ key , array $ tags = [])
61+ {
62+ $ call = $ this ->timeCall (__FUNCTION__ , [$ key , $ tags ]);
4563 $ result = $ call ->result ;
46- $ call ->result = sprintf ('<DATA:%s> ' , gettype ($ result ));
64+
65+ if ($ result ->isHit ()) {
66+ $ call ->result = sprintf ('<DATA:%s> ' , gettype ($ result ->get ()));
67+ } else {
68+ $ call ->result = false ;
69+ }
4770
4871 $ this ->calls [] = $ call ;
4972
5073 return $ result ;
5174 }
5275
53- public function hasItem ($ key )
76+ public function hasItem ($ key, array $ tags = [] )
5477 {
55- $ call = $ this ->timeCall (__FUNCTION__ , [$ key ]);
78+ $ call = $ this ->timeCall (__FUNCTION__ , [$ key, $ tags ]);
5679 $ this ->calls [] = $ call ;
5780
5881 return $ call ->result ;
5982 }
6083
61- public function deleteItem ($ key )
84+ public function deleteItem ($ key, array $ tags = [] )
6285 {
63- $ call = $ this ->timeCall (__FUNCTION__ , [$ key ]);
86+ $ call = $ this ->timeCall (__FUNCTION__ , [$ key, $ tags ]);
6487 $ this ->calls [] = $ call ;
6588
6689 return $ call ->result ;
@@ -78,26 +101,9 @@ public function save(CacheItemInterface $item)
78101 return $ call ->result ;
79102 }
80103
81- /**
82- * @param string $name
83- * @param array $arguments
84- *
85- * @return object
86- */
87- private function timeCall ($ name , array $ arguments = null )
88- {
89- $ start = microtime (true );
90- $ result = call_user_func_array ([$ this ->cachePool , $ name ], $ arguments );
91- $ time = microtime (true ) - $ start ;
92-
93- $ object = (object ) compact ('name ' , 'arguments ' , 'start ' , 'time ' , 'result ' );
94-
95- return $ object ;
96- }
97-
98- public function getItems (array $ keys = [])
104+ public function getItems (array $ keys = [], array $ tags = [])
99105 {
100- $ call = $ this ->timeCall (__FUNCTION__ , [$ keys ]);
106+ $ call = $ this ->timeCall (__FUNCTION__ , [$ keys, $ tags ]);
101107 $ result = $ call ->result ;
102108 $ call ->result = sprintf ('<DATA:%s> ' , gettype ($ result ));
103109
@@ -106,17 +112,17 @@ public function getItems(array $keys = [])
106112 return $ result ;
107113 }
108114
109- public function clear ()
115+ public function clear (array $ tags = [] )
110116 {
111- $ call = $ this ->timeCall (__FUNCTION__ );
117+ $ call = $ this ->timeCall (__FUNCTION__ , [ $ tags ] );
112118 $ this ->calls [] = $ call ;
113119
114120 return $ call ->result ;
115121 }
116122
117- public function deleteItems (array $ keys )
123+ public function deleteItems (array $ keys, array $ tags = [] )
118124 {
119- $ call = $ this ->timeCall (__FUNCTION__ , [$ keys ]);
125+ $ call = $ this ->timeCall (__FUNCTION__ , [$ keys, $ tags ]);
120126 $ this ->calls [] = $ call ;
121127
122128 return $ call ->result ;
0 commit comments