CacheLogger.php
9 months ago
CacheLoggerChain.php
9 months ago
StatisticsCacheLogger.php
9 months ago
index.php
9 months ago
StatisticsCacheLogger.php
99 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Cache\Logging; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\Cache\CollectionCacheKey; |
| 6 | use MailPoetVendor\Doctrine\ORM\Cache\EntityCacheKey; |
| 7 | use MailPoetVendor\Doctrine\ORM\Cache\QueryCacheKey; |
| 8 | use function array_sum; |
| 9 | class StatisticsCacheLogger implements CacheLogger |
| 10 | { |
| 11 | private $cacheMissCountMap = []; |
| 12 | private $cacheHitCountMap = []; |
| 13 | private $cachePutCountMap = []; |
| 14 | public function collectionCacheMiss($regionName, CollectionCacheKey $key) |
| 15 | { |
| 16 | $this->cacheMissCountMap[$regionName] = ($this->cacheMissCountMap[$regionName] ?? 0) + 1; |
| 17 | } |
| 18 | public function collectionCacheHit($regionName, CollectionCacheKey $key) |
| 19 | { |
| 20 | $this->cacheHitCountMap[$regionName] = ($this->cacheHitCountMap[$regionName] ?? 0) + 1; |
| 21 | } |
| 22 | public function collectionCachePut($regionName, CollectionCacheKey $key) |
| 23 | { |
| 24 | $this->cachePutCountMap[$regionName] = ($this->cachePutCountMap[$regionName] ?? 0) + 1; |
| 25 | } |
| 26 | public function entityCacheMiss($regionName, EntityCacheKey $key) |
| 27 | { |
| 28 | $this->cacheMissCountMap[$regionName] = ($this->cacheMissCountMap[$regionName] ?? 0) + 1; |
| 29 | } |
| 30 | public function entityCacheHit($regionName, EntityCacheKey $key) |
| 31 | { |
| 32 | $this->cacheHitCountMap[$regionName] = ($this->cacheHitCountMap[$regionName] ?? 0) + 1; |
| 33 | } |
| 34 | public function entityCachePut($regionName, EntityCacheKey $key) |
| 35 | { |
| 36 | $this->cachePutCountMap[$regionName] = ($this->cachePutCountMap[$regionName] ?? 0) + 1; |
| 37 | } |
| 38 | public function queryCacheHit($regionName, QueryCacheKey $key) |
| 39 | { |
| 40 | $this->cacheHitCountMap[$regionName] = ($this->cacheHitCountMap[$regionName] ?? 0) + 1; |
| 41 | } |
| 42 | public function queryCacheMiss($regionName, QueryCacheKey $key) |
| 43 | { |
| 44 | $this->cacheMissCountMap[$regionName] = ($this->cacheMissCountMap[$regionName] ?? 0) + 1; |
| 45 | } |
| 46 | public function queryCachePut($regionName, QueryCacheKey $key) |
| 47 | { |
| 48 | $this->cachePutCountMap[$regionName] = ($this->cachePutCountMap[$regionName] ?? 0) + 1; |
| 49 | } |
| 50 | public function getRegionHitCount($regionName) |
| 51 | { |
| 52 | return $this->cacheHitCountMap[$regionName] ?? 0; |
| 53 | } |
| 54 | public function getRegionMissCount($regionName) |
| 55 | { |
| 56 | return $this->cacheMissCountMap[$regionName] ?? 0; |
| 57 | } |
| 58 | public function getRegionPutCount($regionName) |
| 59 | { |
| 60 | return $this->cachePutCountMap[$regionName] ?? 0; |
| 61 | } |
| 62 | public function getRegionsMiss() |
| 63 | { |
| 64 | return $this->cacheMissCountMap; |
| 65 | } |
| 66 | public function getRegionsHit() |
| 67 | { |
| 68 | return $this->cacheHitCountMap; |
| 69 | } |
| 70 | public function getRegionsPut() |
| 71 | { |
| 72 | return $this->cachePutCountMap; |
| 73 | } |
| 74 | public function clearRegionStats($regionName) |
| 75 | { |
| 76 | $this->cachePutCountMap[$regionName] = 0; |
| 77 | $this->cacheHitCountMap[$regionName] = 0; |
| 78 | $this->cacheMissCountMap[$regionName] = 0; |
| 79 | } |
| 80 | public function clearStats() |
| 81 | { |
| 82 | $this->cachePutCountMap = []; |
| 83 | $this->cacheHitCountMap = []; |
| 84 | $this->cacheMissCountMap = []; |
| 85 | } |
| 86 | public function getPutCount() |
| 87 | { |
| 88 | return array_sum($this->cachePutCountMap); |
| 89 | } |
| 90 | public function getHitCount() |
| 91 | { |
| 92 | return array_sum($this->cacheHitCountMap); |
| 93 | } |
| 94 | public function getMissCount() |
| 95 | { |
| 96 | return array_sum($this->cacheMissCountMap); |
| 97 | } |
| 98 | } |
| 99 |