@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | protected CacheInterface $storage, |
26 | 26 | protected ?EventDispatcherInterface $dispatcher = null, |
27 | 27 | protected ?string $prefix = null, |
28 | - ) {} |
|
28 | + ) { |
|
29 | +} |
|
29 | 30 | |
30 | 31 | public function get(string $key, mixed $default = null): mixed |
31 | 32 | { |
@@ -35,7 +36,8 @@ discard block |
||
35 | 36 | |
36 | 37 | $value = $this->storage->get($key); |
37 | 38 | |
38 | - if ($value === null) { |
|
39 | + if ($value === null) |
|
40 | + { |
|
39 | 41 | $this->dispatcher?->dispatch(new CacheMissed($key)); |
40 | 42 | |
41 | 43 | return $default; |
@@ -89,7 +91,8 @@ discard block |
||
89 | 91 | { |
90 | 92 | $array = []; |
91 | 93 | // Resolve keys and dispatch events |
92 | - foreach ($keys as $key) { |
|
94 | + foreach ($keys as $key) |
|
95 | + { |
|
93 | 96 | $key = $this->resolveKey($key); |
94 | 97 | $this->dispatcher?->dispatch(new CacheRetrieving($key)); |
95 | 98 | // Fill resulting array with default values |
@@ -99,16 +102,21 @@ discard block |
||
99 | 102 | // If no dispatcher is set, we can skip the loop with events |
100 | 103 | // to save some CPU cycles |
101 | 104 | $keys = \array_keys($array); |
102 | - if ($this->dispatcher === null) { |
|
105 | + if ($this->dispatcher === null) |
|
106 | + { |
|
103 | 107 | return $this->storage->getMultiple($keys, $default); |
104 | 108 | } |
105 | 109 | |
106 | 110 | $result = $this->storage->getMultiple($keys); |
107 | 111 | |
108 | - foreach ($result as $key => $value) { |
|
109 | - if ($value === null) { |
|
112 | + foreach ($result as $key => $value) |
|
113 | + { |
|
114 | + if ($value === null) |
|
115 | + { |
|
110 | 116 | $this->dispatcher->dispatch(new CacheMissed($key)); |
111 | - } else { |
|
117 | + } |
|
118 | + else |
|
119 | + { |
|
112 | 120 | // Replace default value with actual value in the resulting array |
113 | 121 | $array[$key] = $value; |
114 | 122 | $this->dispatcher->dispatch(new CacheHit($key, $value)); |
@@ -123,7 +131,8 @@ discard block |
||
123 | 131 | $dispatcher = $this->dispatcher; |
124 | 132 | $array = []; |
125 | 133 | // Resolve keys and dispatch events |
126 | - foreach ($values as $key => $value) { |
|
134 | + foreach ($values as $key => $value) |
|
135 | + { |
|
127 | 136 | $key = $this->resolveKey($key); |
128 | 137 | $dispatcher?->dispatch(new KeyWriting($key, $value)); |
129 | 138 | $array[$key] = $value; |
@@ -148,7 +157,8 @@ discard block |
||
148 | 157 | |
149 | 158 | $array = []; |
150 | 159 | // Resolve keys and dispatch events |
151 | - foreach ($keys as $key) { |
|
160 | + foreach ($keys as $key) |
|
161 | + { |
|
152 | 162 | $key = $this->resolveKey($key); |
153 | 163 | $dispatcher?->dispatch(new KeyDeleting($key)); |
154 | 164 | $array[] = $key; |