1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Cache\Logging; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Cache\CollectionCacheKey; |
8
|
|
|
use Doctrine\ORM\Cache\EntityCacheKey; |
9
|
|
|
use Doctrine\ORM\Cache\QueryCacheKey; |
10
|
|
|
use function array_sum; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Provide basic second level cache statistics. |
14
|
|
|
*/ |
15
|
|
|
class StatisticsCacheLogger implements CacheLogger |
16
|
|
|
{ |
17
|
|
|
/** @var int[] */ |
18
|
|
|
private $cacheMissCountMap = []; |
19
|
|
|
|
20
|
|
|
/** @var int[] */ |
21
|
|
|
private $cacheHitCountMap = []; |
22
|
|
|
|
23
|
|
|
/** @var int[] */ |
24
|
|
|
private $cachePutCountMap = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
17 |
|
public function collectionCacheMiss($regionName, CollectionCacheKey $key) |
30
|
|
|
{ |
31
|
17 |
|
$this->cacheMissCountMap[$regionName] = isset($this->cacheMissCountMap[$regionName]) |
32
|
3 |
|
? $this->cacheMissCountMap[$regionName] + 1 |
33
|
17 |
|
: 1; |
34
|
17 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
17 |
|
public function collectionCacheHit($regionName, CollectionCacheKey $key) |
40
|
|
|
{ |
41
|
17 |
|
$this->cacheHitCountMap[$regionName] = isset($this->cacheHitCountMap[$regionName]) |
42
|
2 |
|
? $this->cacheHitCountMap[$regionName] + 1 |
43
|
17 |
|
: 1; |
44
|
17 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
47 |
|
public function collectionCachePut($regionName, CollectionCacheKey $key) |
50
|
|
|
{ |
51
|
47 |
|
$this->cachePutCountMap[$regionName] = isset($this->cachePutCountMap[$regionName]) |
52
|
45 |
|
? $this->cachePutCountMap[$regionName] + 1 |
53
|
47 |
|
: 1; |
54
|
47 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
35 |
|
public function entityCacheMiss($regionName, EntityCacheKey $key) |
60
|
|
|
{ |
61
|
35 |
|
$this->cacheMissCountMap[$regionName] = isset($this->cacheMissCountMap[$regionName]) |
62
|
16 |
|
? $this->cacheMissCountMap[$regionName] + 1 |
63
|
33 |
|
: 1; |
64
|
35 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
68 |
|
public function entityCacheHit($regionName, EntityCacheKey $key) |
70
|
|
|
{ |
71
|
68 |
|
$this->cacheHitCountMap[$regionName] = isset($this->cacheHitCountMap[$regionName]) |
72
|
35 |
|
? $this->cacheHitCountMap[$regionName] + 1 |
73
|
67 |
|
: 1; |
74
|
68 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
97 |
|
public function entityCachePut($regionName, EntityCacheKey $key) |
80
|
|
|
{ |
81
|
97 |
|
$this->cachePutCountMap[$regionName] = isset($this->cachePutCountMap[$regionName]) |
82
|
90 |
|
? $this->cachePutCountMap[$regionName] + 1 |
83
|
97 |
|
: 1; |
84
|
97 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
29 |
|
public function queryCacheHit($regionName, QueryCacheKey $key) |
90
|
|
|
{ |
91
|
29 |
|
$this->cacheHitCountMap[$regionName] = isset($this->cacheHitCountMap[$regionName]) |
92
|
11 |
|
? $this->cacheHitCountMap[$regionName] + 1 |
93
|
18 |
|
: 1; |
94
|
29 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
39 |
|
public function queryCacheMiss($regionName, QueryCacheKey $key) |
100
|
|
|
{ |
101
|
39 |
|
$this->cacheMissCountMap[$regionName] = isset($this->cacheMissCountMap[$regionName]) |
102
|
15 |
|
? $this->cacheMissCountMap[$regionName] + 1 |
103
|
39 |
|
: 1; |
104
|
39 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
39 |
|
public function queryCachePut($regionName, QueryCacheKey $key) |
110
|
|
|
{ |
111
|
39 |
|
$this->cachePutCountMap[$regionName] = isset($this->cachePutCountMap[$regionName]) |
112
|
19 |
|
? $this->cachePutCountMap[$regionName] + 1 |
113
|
29 |
|
: 1; |
114
|
39 |
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get the number of entries successfully retrieved from cache. |
118
|
|
|
* |
119
|
|
|
* @param string $regionName The name of the cache region. |
120
|
|
|
* |
121
|
|
|
* @return int |
122
|
|
|
*/ |
123
|
17 |
|
public function getRegionHitCount($regionName) |
124
|
|
|
{ |
125
|
17 |
|
return $this->cacheHitCountMap[$regionName] ?? 0; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get the number of cached entries *not* found in cache. |
130
|
|
|
* |
131
|
|
|
* @param string $regionName The name of the cache region. |
132
|
|
|
* |
133
|
|
|
* @return int |
134
|
|
|
*/ |
135
|
14 |
|
public function getRegionMissCount($regionName) |
136
|
|
|
{ |
137
|
14 |
|
return $this->cacheMissCountMap[$regionName] ?? 0; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get the number of cacheable entries put in cache. |
142
|
|
|
* |
143
|
|
|
* @param string $regionName The name of the cache region. |
144
|
|
|
* |
145
|
|
|
* @return int |
146
|
|
|
*/ |
147
|
18 |
|
public function getRegionPutCount($regionName) |
148
|
|
|
{ |
149
|
18 |
|
return $this->cachePutCountMap[$regionName] ?? 0; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return int[] |
154
|
|
|
*/ |
155
|
1 |
|
public function getRegionsMiss() |
156
|
|
|
{ |
157
|
1 |
|
return $this->cacheMissCountMap; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return int[] |
162
|
|
|
*/ |
163
|
1 |
|
public function getRegionsHit() |
164
|
|
|
{ |
165
|
1 |
|
return $this->cacheHitCountMap; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return int[] |
170
|
|
|
*/ |
171
|
1 |
|
public function getRegionsPut() |
172
|
|
|
{ |
173
|
1 |
|
return $this->cachePutCountMap; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Clear region statistics |
178
|
|
|
* |
179
|
|
|
* @param string $regionName The name of the cache region. |
180
|
|
|
*/ |
181
|
2 |
|
public function clearRegionStats($regionName) |
182
|
|
|
{ |
183
|
2 |
|
$this->cachePutCountMap[$regionName] = 0; |
184
|
2 |
|
$this->cacheHitCountMap[$regionName] = 0; |
185
|
2 |
|
$this->cacheMissCountMap[$regionName] = 0; |
186
|
2 |
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Clear all statistics |
190
|
|
|
*/ |
191
|
27 |
|
public function clearStats() |
192
|
|
|
{ |
193
|
27 |
|
$this->cachePutCountMap = []; |
194
|
27 |
|
$this->cacheHitCountMap = []; |
195
|
27 |
|
$this->cacheMissCountMap = []; |
196
|
27 |
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Get the total number of put in cache. |
200
|
|
|
* |
201
|
|
|
* @return int |
202
|
|
|
*/ |
203
|
19 |
|
public function getPutCount() |
204
|
|
|
{ |
205
|
19 |
|
return array_sum($this->cachePutCountMap); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get the total number of entries successfully retrieved from cache. |
210
|
|
|
* |
211
|
|
|
* @return int |
212
|
|
|
*/ |
213
|
18 |
|
public function getHitCount() |
214
|
|
|
{ |
215
|
18 |
|
return array_sum($this->cacheHitCountMap); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Get the total number of cached entries *not* found in cache. |
220
|
|
|
* |
221
|
|
|
* @return int |
222
|
|
|
*/ |
223
|
21 |
|
public function getMissCount() |
224
|
|
|
{ |
225
|
21 |
|
return array_sum($this->cacheMissCountMap); |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|