summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Cache/Logging/StatisticsCacheLogger.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/orm/src/Cache/Logging/StatisticsCacheLogger.php')
-rw-r--r--vendor/doctrine/orm/src/Cache/Logging/StatisticsCacheLogger.php174
1 files changed, 174 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Cache/Logging/StatisticsCacheLogger.php b/vendor/doctrine/orm/src/Cache/Logging/StatisticsCacheLogger.php
new file mode 100644
index 0000000..092104e
--- /dev/null
+++ b/vendor/doctrine/orm/src/Cache/Logging/StatisticsCacheLogger.php
@@ -0,0 +1,174 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Cache\Logging;
6
7use Doctrine\ORM\Cache\CollectionCacheKey;
8use Doctrine\ORM\Cache\EntityCacheKey;
9use Doctrine\ORM\Cache\QueryCacheKey;
10
11use function array_sum;
12
13/**
14 * Provide basic second level cache statistics.
15 */
16class StatisticsCacheLogger implements CacheLogger
17{
18 /** @var array<string, int> */
19 private array $cacheMissCountMap = [];
20
21 /** @var array<string, int> */
22 private array $cacheHitCountMap = [];
23
24 /** @var array<string, int> */
25 private array $cachePutCountMap = [];
26
27 public function collectionCacheMiss(string $regionName, CollectionCacheKey $key): void
28 {
29 $this->cacheMissCountMap[$regionName]
30 = ($this->cacheMissCountMap[$regionName] ?? 0) + 1;
31 }
32
33 public function collectionCacheHit(string $regionName, CollectionCacheKey $key): void
34 {
35 $this->cacheHitCountMap[$regionName]
36 = ($this->cacheHitCountMap[$regionName] ?? 0) + 1;
37 }
38
39 public function collectionCachePut(string $regionName, CollectionCacheKey $key): void
40 {
41 $this->cachePutCountMap[$regionName]
42 = ($this->cachePutCountMap[$regionName] ?? 0) + 1;
43 }
44
45 public function entityCacheMiss(string $regionName, EntityCacheKey $key): void
46 {
47 $this->cacheMissCountMap[$regionName]
48 = ($this->cacheMissCountMap[$regionName] ?? 0) + 1;
49 }
50
51 public function entityCacheHit(string $regionName, EntityCacheKey $key): void
52 {
53 $this->cacheHitCountMap[$regionName]
54 = ($this->cacheHitCountMap[$regionName] ?? 0) + 1;
55 }
56
57 public function entityCachePut(string $regionName, EntityCacheKey $key): void
58 {
59 $this->cachePutCountMap[$regionName]
60 = ($this->cachePutCountMap[$regionName] ?? 0) + 1;
61 }
62
63 public function queryCacheHit(string $regionName, QueryCacheKey $key): void
64 {
65 $this->cacheHitCountMap[$regionName]
66 = ($this->cacheHitCountMap[$regionName] ?? 0) + 1;
67 }
68
69 public function queryCacheMiss(string $regionName, QueryCacheKey $key): void
70 {
71 $this->cacheMissCountMap[$regionName]
72 = ($this->cacheMissCountMap[$regionName] ?? 0) + 1;
73 }
74
75 public function queryCachePut(string $regionName, QueryCacheKey $key): void
76 {
77 $this->cachePutCountMap[$regionName]
78 = ($this->cachePutCountMap[$regionName] ?? 0) + 1;
79 }
80
81 /**
82 * Get the number of entries successfully retrieved from cache.
83 *
84 * @param string $regionName The name of the cache region.
85 */
86 public function getRegionHitCount(string $regionName): int
87 {
88 return $this->cacheHitCountMap[$regionName] ?? 0;
89 }
90
91 /**
92 * Get the number of cached entries *not* found in cache.
93 *
94 * @param string $regionName The name of the cache region.
95 */
96 public function getRegionMissCount(string $regionName): int
97 {
98 return $this->cacheMissCountMap[$regionName] ?? 0;
99 }
100
101 /**
102 * Get the number of cacheable entries put in cache.
103 *
104 * @param string $regionName The name of the cache region.
105 */
106 public function getRegionPutCount(string $regionName): int
107 {
108 return $this->cachePutCountMap[$regionName] ?? 0;
109 }
110
111 /** @return array<string, int> */
112 public function getRegionsMiss(): array
113 {
114 return $this->cacheMissCountMap;
115 }
116
117 /** @return array<string, int> */
118 public function getRegionsHit(): array
119 {
120 return $this->cacheHitCountMap;
121 }
122
123 /** @return array<string, int> */
124 public function getRegionsPut(): array
125 {
126 return $this->cachePutCountMap;
127 }
128
129 /**
130 * Clear region statistics
131 *
132 * @param string $regionName The name of the cache region.
133 */
134 public function clearRegionStats(string $regionName): void
135 {
136 $this->cachePutCountMap[$regionName] = 0;
137 $this->cacheHitCountMap[$regionName] = 0;
138 $this->cacheMissCountMap[$regionName] = 0;
139 }
140
141 /**
142 * Clear all statistics
143 */
144 public function clearStats(): void
145 {
146 $this->cachePutCountMap = [];
147 $this->cacheHitCountMap = [];
148 $this->cacheMissCountMap = [];
149 }
150
151 /**
152 * Get the total number of put in cache.
153 */
154 public function getPutCount(): int
155 {
156 return array_sum($this->cachePutCountMap);
157 }
158
159 /**
160 * Get the total number of entries successfully retrieved from cache.
161 */
162 public function getHitCount(): int
163 {
164 return array_sum($this->cacheHitCountMap);
165 }
166
167 /**
168 * Get the total number of cached entries *not* found in cache.
169 */
170 public function getMissCount(): int
171 {
172 return array_sum($this->cacheMissCountMap);
173 }
174}