@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | protected CacheInterface $storage, |
| 21 | 21 | protected ?EventDispatcherInterface $dispatcher = null, |
| 22 | 22 | protected ?string $prefix = null |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function get(string $key, mixed $default = null): mixed |
| 27 | 27 | { |
| 28 | 28 | $value = $this->storage->get($this->resolveKey($key)); |
| 29 | 29 | |
| 30 | - if ($value === null) { |
|
| 30 | + if ($value === null){ |
|
| 31 | 31 | $this->dispatcher?->dispatch(new CacheMissed($this->resolveKey($key))); |
| 32 | 32 | |
| 33 | 33 | return $default; |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | return $value; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool |
|
| 41 | + public function set(string $key, mixed $value, \DateInterval | int | null $ttl = null): bool |
|
| 42 | 42 | { |
| 43 | 43 | $result = $this->storage->set($this->resolveKey($key), $value, $ttl); |
| 44 | 44 | |
| 45 | - if ($result) { |
|
| 45 | + if ($result){ |
|
| 46 | 46 | $this->dispatcher?->dispatch(new KeyWritten($this->resolveKey($key), $value)); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | { |
| 54 | 54 | $result = $this->storage->delete($this->resolveKey($key)); |
| 55 | 55 | |
| 56 | - if ($result) { |
|
| 56 | + if ($result){ |
|
| 57 | 57 | $this->dispatcher?->dispatch(new KeyDeleted($this->resolveKey($key))); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -69,18 +69,18 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $result = []; |
| 71 | 71 | |
| 72 | - foreach ($keys as $key) { |
|
| 72 | + foreach ($keys as $key){ |
|
| 73 | 73 | $result[$key] = $this->get($key, $default); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | return $result; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool |
|
| 79 | + public function setMultiple(iterable $values, \DateInterval | int | null $ttl = null): bool |
|
| 80 | 80 | { |
| 81 | 81 | $state = null; |
| 82 | 82 | |
| 83 | - foreach ($values as $key => $value) { |
|
| 83 | + foreach ($values as $key => $value){ |
|
| 84 | 84 | $result = $this->set($key, $value, $ttl); |
| 85 | 85 | $state = \is_null($state) ? $result : $result && $state; |
| 86 | 86 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | public function deleteMultiple(iterable $keys): bool |
| 92 | 92 | { |
| 93 | 93 | $state = null; |
| 94 | - foreach ($keys as $key) { |
|
| 94 | + foreach ($keys as $key){ |
|
| 95 | 95 | $result = $this->delete($key); |
| 96 | 96 | $state = \is_null($state) ? $result : $result && $state; |
| 97 | 97 | } |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | private function resolveKey(string $key): string |
| 113 | 113 | { |
| 114 | - if (!empty($this->prefix)) { |
|
| 115 | - return $this->prefix . $key; |
|
| 114 | + if (!empty($this->prefix)){ |
|
| 115 | + return $this->prefix.$key; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | return $key; |
@@ -27,7 +27,8 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | $value = $this->storage->get($this->resolveKey($key)); |
| 29 | 29 | |
| 30 | - if ($value === null) { |
|
| 30 | + if ($value === null) |
|
| 31 | + { |
|
| 31 | 32 | $this->dispatcher?->dispatch(new CacheMissed($this->resolveKey($key))); |
| 32 | 33 | |
| 33 | 34 | return $default; |
@@ -42,7 +43,8 @@ discard block |
||
| 42 | 43 | { |
| 43 | 44 | $result = $this->storage->set($this->resolveKey($key), $value, $ttl); |
| 44 | 45 | |
| 45 | - if ($result) { |
|
| 46 | + if ($result) |
|
| 47 | + { |
|
| 46 | 48 | $this->dispatcher?->dispatch(new KeyWritten($this->resolveKey($key), $value)); |
| 47 | 49 | } |
| 48 | 50 | |
@@ -53,7 +55,8 @@ discard block |
||
| 53 | 55 | { |
| 54 | 56 | $result = $this->storage->delete($this->resolveKey($key)); |
| 55 | 57 | |
| 56 | - if ($result) { |
|
| 58 | + if ($result) |
|
| 59 | + { |
|
| 57 | 60 | $this->dispatcher?->dispatch(new KeyDeleted($this->resolveKey($key))); |
| 58 | 61 | } |
| 59 | 62 | |
@@ -69,7 +72,8 @@ discard block |
||
| 69 | 72 | { |
| 70 | 73 | $result = []; |
| 71 | 74 | |
| 72 | - foreach ($keys as $key) { |
|
| 75 | + foreach ($keys as $key) |
|
| 76 | + { |
|
| 73 | 77 | $result[$key] = $this->get($key, $default); |
| 74 | 78 | } |
| 75 | 79 | |
@@ -80,7 +84,8 @@ discard block |
||
| 80 | 84 | { |
| 81 | 85 | $state = null; |
| 82 | 86 | |
| 83 | - foreach ($values as $key => $value) { |
|
| 87 | + foreach ($values as $key => $value) |
|
| 88 | + { |
|
| 84 | 89 | $result = $this->set($key, $value, $ttl); |
| 85 | 90 | $state = \is_null($state) ? $result : $result && $state; |
| 86 | 91 | } |
@@ -91,7 +96,8 @@ discard block |
||
| 91 | 96 | public function deleteMultiple(iterable $keys): bool |
| 92 | 97 | { |
| 93 | 98 | $state = null; |
| 94 | - foreach ($keys as $key) { |
|
| 99 | + foreach ($keys as $key) |
|
| 100 | + { |
|
| 95 | 101 | $result = $this->delete($key); |
| 96 | 102 | $state = \is_null($state) ? $result : $result && $state; |
| 97 | 103 | } |
@@ -111,7 +117,8 @@ discard block |
||
| 111 | 117 | |
| 112 | 118 | private function resolveKey(string $key): string |
| 113 | 119 | { |
| 114 | - if (!empty($this->prefix)) { |
|
| 120 | + if (!empty($this->prefix)) |
|
| 121 | + { |
|
| 115 | 122 | return $this->prefix . $key; |
| 116 | 123 | } |
| 117 | 124 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | private readonly CacheConfig $config, |
| 20 | 20 | private readonly FactoryInterface $factory, |
| 21 | 21 | private readonly ?EventDispatcherInterface $dispatcher = null, |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function storage(?string $name = null): CacheInterface |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | $storage = $this->config->getAliases()[$name] ?? $name; |
| 31 | 31 | |
| 32 | 32 | $prefix = null; |
| 33 | - if (\is_array($storage)) { |
|
| 33 | + if (\is_array($storage)){ |
|
| 34 | 34 | $prefix = !empty($storage['prefix']) ? $storage['prefix'] : null; |
| 35 | 35 | $storage = $storage['storage']; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if(!isset($this->storages[$storage])) { |
|
| 38 | + if (!isset($this->storages[$storage])){ |
|
| 39 | 39 | $this->storages[$storage] = $this->resolve($storage); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -30,12 +30,14 @@ |
||
| 30 | 30 | $storage = $this->config->getAliases()[$name] ?? $name; |
| 31 | 31 | |
| 32 | 32 | $prefix = null; |
| 33 | - if (\is_array($storage)) { |
|
| 33 | + if (\is_array($storage)) |
|
| 34 | + { |
|
| 34 | 35 | $prefix = !empty($storage['prefix']) ? $storage['prefix'] : null; |
| 35 | 36 | $storage = $storage['storage']; |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | - if(!isset($this->storages[$storage])) { |
|
| 39 | + if(!isset($this->storages[$storage])) |
|
| 40 | + { |
|
| 39 | 41 | $this->storages[$storage] = $this->resolve($storage); |
| 40 | 42 | } |
| 41 | 43 | |