@@ -44,8 +44,22 @@ public function collect(Request $request, Response $response, \Exception $except
44
44
{
45
45
parent ::collect ($ request , $ response , $ exception );
46
46
47
- $ errors = array ();
47
+ $ errors = array ();
48
48
$ entities = array ();
49
+ $ caches = array (
50
+ 'enabled ' => false ,
51
+ 'log_enabled ' => false ,
52
+ 'counts ' => array (
53
+ 'puts ' => 0 ,
54
+ 'hits ' => 0 ,
55
+ 'misses ' => 0 ,
56
+ ),
57
+ 'regions ' => array (
58
+ 'puts ' => array (),
59
+ 'hits ' => array (),
60
+ 'misses ' => array (),
61
+ ),
62
+ );
49
63
50
64
foreach ($ this ->registry ->getManagers () as $ name => $ em ) {
51
65
$ entities [$ name ] = array ();
@@ -62,10 +76,62 @@ public function collect(Request $request, Response $response, \Exception $except
62
76
$ errors [$ name ][$ class ->getName ()] = $ classErrors ;
63
77
}
64
78
}
79
+
80
+ /** @var $emConfig \Doctrine\ORM\Configuration */
81
+ $ emConfig = $ em ->getConfiguration ();
82
+ $ slcEnabled = $ emConfig ->isSecondLevelCacheEnabled ();
83
+
84
+ if ( ! $ slcEnabled ) {
85
+ continue ;
86
+ }
87
+
88
+ $ caches ['enabled ' ] = true ;
89
+
90
+ /** @var $cacheConfiguration \Doctrine\ORM\Cache\CacheConfiguration */
91
+ /** @var $clacheLoggerChain \Doctrine\ORM\Cache\Logging\CacheLoggerChain */
92
+ /** @var $cacheLoggerStats \Doctrine\ORM\Cache\Logging\StatisticsCacheLogger */
93
+ $ cacheConfiguration = $ emConfig ->getSecondLevelCacheConfiguration ();
94
+ $ cacheLoggerChain = $ cacheConfiguration ->getCacheLogger ();
95
+ $ cacheLoggerStats = $ cacheLoggerChain ->getLogger ('statistics ' );
96
+
97
+ if ( ! $ cacheLoggerStats ) {
98
+ continue ;
99
+ }
100
+
101
+ $ caches ['log_enabled ' ] = true ;
102
+
103
+ $ caches ['counts ' ]['puts ' ] += $ cacheLoggerStats ->getPutCount ();
104
+ $ caches ['counts ' ]['hits ' ] += $ cacheLoggerStats ->getHitCount ();
105
+ $ caches ['counts ' ]['misses ' ] += $ cacheLoggerStats ->getMissCount ();
106
+
107
+ foreach ($ cacheLoggerStats ->getRegionsPut () as $ key => $ value ) {
108
+ if ( ! isset ($ caches ['regions ' ]['puts ' ][$ key ])) {
109
+ $ caches ['regions ' ]['puts ' ][$ key ] = 0 ;
110
+ }
111
+
112
+ $ caches ['regions ' ]['puts ' ][$ key ] += $ value ;
113
+ }
114
+
115
+ foreach ($ cacheLoggerStats ->getRegionsHit () as $ key => $ value ) {
116
+ if ( ! isset ($ caches ['regions ' ]['hits ' ][$ key ])) {
117
+ $ caches ['regions ' ]['hits ' ][$ key ] = 0 ;
118
+ }
119
+
120
+ $ caches ['regions ' ]['hits ' ][$ key ] += $ value ;
121
+ }
122
+
123
+ foreach ($ cacheLoggerStats ->getRegionsMiss () as $ key => $ value ) {
124
+ if ( ! isset ($ caches ['regions ' ]['misses ' ][$ key ])) {
125
+ $ caches ['regions ' ]['misses ' ][$ key ] = 0 ;
126
+ }
127
+
128
+ $ caches ['regions ' ]['misses ' ][$ key ] += $ value ;
129
+ }
65
130
}
66
131
67
132
$ this ->data ['entities ' ] = $ entities ;
68
- $ this ->data ['errors ' ] = $ errors ;
133
+ $ this ->data ['errors ' ] = $ errors ;
134
+ $ this ->data ['caches ' ] = $ caches ;
69
135
}
70
136
71
137
public function getEntities ()
@@ -78,6 +144,36 @@ public function getMappingErrors()
78
144
return $ this ->data ['errors ' ];
79
145
}
80
146
147
+ public function getCacheHitsCount ()
148
+ {
149
+ return $ this ->data ['caches ' ]['counts ' ]['hits ' ];
150
+ }
151
+
152
+ public function getCachePutsCount ()
153
+ {
154
+ return $ this ->data ['caches ' ]['counts ' ]['puts ' ];
155
+ }
156
+
157
+ public function getCacheMissesCount ()
158
+ {
159
+ return $ this ->data ['caches ' ]['counts ' ]['misses ' ];
160
+ }
161
+
162
+ public function getCacheEnabled ()
163
+ {
164
+ return $ this ->data ['caches ' ]['enabled ' ];
165
+ }
166
+
167
+ public function getCacheRegions ()
168
+ {
169
+ return $ this ->data ['caches ' ]['regions ' ];
170
+ }
171
+
172
+ public function getCacheCounts ()
173
+ {
174
+ return $ this ->data ['caches ' ]['counts ' ];
175
+ }
176
+
81
177
public function getInvalidEntityCount ()
82
178
{
83
179
if (null === $ this ->invalidEntityCount ) {
0 commit comments