@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WebStream\Cache\Driver; |
| 3 | 3 | |
| 4 | -use WebStream\DI\Injector; |
|
| 5 | 4 | use WebStream\Module\Container; |
| 6 | 5 | |
| 7 | 6 | /** |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | public function __construct(Container $cacheContainer) |
| 31 | 31 | { |
| 32 | 32 | $this->cacheContainer = $cacheContainer; |
| 33 | - $this->cachePrefix = $this->cacheContainer->cachePrefix . '.' . $this->cacheContainer->classPrefix . '.'; |
|
| 33 | + $this->cachePrefix = $this->cacheContainer->cachePrefix.'.'.$this->cacheContainer->classPrefix.'.'; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $this->logger->info("Execute cache save: " . $key); |
|
| 64 | + $this->logger->info("Execute cache save: ".$key); |
|
| 65 | 65 | |
| 66 | 66 | return $result; |
| 67 | 67 | } |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $result = $this->cacheContainer->driver->get($key); |
| 79 | - $this->logger->info("Execute cache read: " . $key); |
|
| 79 | + $this->logger->info("Execute cache read: ".$key); |
|
| 80 | 80 | |
| 81 | 81 | if ($result !== false) { |
| 82 | - $this->logger->info("Execute cache read: " . $key); |
|
| 82 | + $this->logger->info("Execute cache read: ".$key); |
|
| 83 | 83 | } else { |
| 84 | - $this->logger->warn("Failed to read cache: " . $key); |
|
| 84 | + $this->logger->warn("Failed to read cache: ".$key); |
|
| 85 | 85 | $result = null; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -98,10 +98,10 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | if ($this->cacheContainer->driver->delete($key) > 0) { |
| 101 | - $this->logger->info("Execute cache cleared: " . $key); |
|
| 101 | + $this->logger->info("Execute cache cleared: ".$key); |
|
| 102 | 102 | return true; |
| 103 | 103 | } else { |
| 104 | - $this->logger->warn("Failed to clear cache: " . $key); |
|
| 104 | + $this->logger->warn("Failed to clear cache: ".$key); |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -124,10 +124,10 @@ discard block |
||
| 124 | 124 | $this->cacheContainer->driver->setOption($this->cacheContainer->redisOptPrefix, $this->cachePrefix); |
| 125 | 125 | |
| 126 | 126 | if ($result > 0) { |
| 127 | - $this->logger->info("Execute all cache cleared: " . $this->cachePrefix . "*"); |
|
| 127 | + $this->logger->info("Execute all cache cleared: ".$this->cachePrefix."*"); |
|
| 128 | 128 | return true; |
| 129 | 129 | } else { |
| 130 | - $this->logger->warn("Failed to clear all cache: " . $this->cachePrefix . "*"); |
|
| 130 | + $this->logger->warn("Failed to clear all cache: ".$this->cachePrefix."*"); |
|
| 131 | 131 | return false; |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | if (!$this->isAvailableCacheLibrary()) { |
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | - $key = $this->cacheContainer->cachePrefix . $key; |
|
| 43 | + $key = $this->cacheContainer->cachePrefix.$key; |
|
| 44 | 44 | $writer = null; |
| 45 | 45 | $isAppend = !$overwrite; |
| 46 | 46 | |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | ]); |
| 52 | 52 | |
| 53 | 53 | try { |
| 54 | - $file = new File($this->cacheContainer->cacheDir . '/' . $key . '.cache'); |
|
| 54 | + $file = new File($this->cacheContainer->cacheDir.'/'.$key.'.cache'); |
|
| 55 | 55 | $writer = $this->cacheContainer->ioContainer->fileWriter->getWriter($file, $isAppend); |
| 56 | 56 | $writer->write($value); |
| 57 | - $this->logger->info("Execute cache save: " . $key); |
|
| 57 | + $this->logger->info("Execute cache save: ".$key); |
|
| 58 | 58 | return true; |
| 59 | 59 | } catch (IOException $e) { |
| 60 | 60 | $this->logger->warn($e->getMessage()); |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | if (!$this->isAvailableCacheLibrary()) { |
| 79 | 79 | return null; |
| 80 | 80 | } |
| 81 | - $key = $this->cacheContainer->cachePrefix . $key; |
|
| 81 | + $key = $this->cacheContainer->cachePrefix.$key; |
|
| 82 | 82 | $value = null; |
| 83 | 83 | $reader = null; |
| 84 | - $file = new File($this->cacheContainer->cacheDir . '/' . $key . '.cache'); |
|
| 84 | + $file = new File($this->cacheContainer->cacheDir.'/'.$key.'.cache'); |
|
| 85 | 85 | |
| 86 | 86 | if ($file->isReadable()) { |
| 87 | 87 | try { |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | $data = $this->decode($reader->read()); |
| 91 | 91 | if ($data['ttl'] > 0) { |
| 92 | 92 | if (time() > $data['time'] + $data['ttl']) { |
| 93 | - $this->logger->info("Expired cache: " . $key); |
|
| 93 | + $this->logger->info("Expired cache: ".$key); |
|
| 94 | 94 | $file->delete(); |
| 95 | 95 | } |
| 96 | 96 | } else { |
| 97 | 97 | $value = $data['data']; |
| 98 | - $this->logger->info("Execute cache read: " . $key); |
|
| 98 | + $this->logger->info("Execute cache read: ".$key); |
|
| 99 | 99 | } |
| 100 | 100 | } catch (IOException $e) { |
| 101 | 101 | $this->logger->warn($e->getMessage()); |
@@ -121,15 +121,15 @@ discard block |
||
| 121 | 121 | if (!$this->isAvailableCacheLibrary()) { |
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | - $key = $this->cacheContainer->cachePrefix . $key; |
|
| 124 | + $key = $this->cacheContainer->cachePrefix.$key; |
|
| 125 | 125 | $result = false; |
| 126 | 126 | |
| 127 | - $file = new File($this->cacheContainer->cacheDir . '/' . $key . '.cache'); |
|
| 127 | + $file = new File($this->cacheContainer->cacheDir.'/'.$key.'.cache'); |
|
| 128 | 128 | if ($file->isWritable()) { |
| 129 | 129 | $result = $file->delete(); |
| 130 | - $this->logger->info("Execute cache cleared: " . $key); |
|
| 130 | + $this->logger->info("Execute cache cleared: ".$key); |
|
| 131 | 131 | } else { |
| 132 | - $this->logger->warn("Failed to clear cache: " . $key); |
|
| 132 | + $this->logger->warn("Failed to clear cache: ".$key); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | return $result; |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | $file = new File($filepath); |
| 155 | 155 | if ($file->isWritable()) { |
| 156 | 156 | if ($file->delete()) { |
| 157 | - $this->logger->info("Execute cache cleared: " . $this->cacheContainer->cachePrefix . "*"); |
|
| 157 | + $this->logger->info("Execute cache cleared: ".$this->cacheContainer->cachePrefix."*"); |
|
| 158 | 158 | } else { |
| 159 | - $this->logger->warn("Failed to clear cache: " . $this->cacheContainer->cachePrefix . "*"); |
|
| 159 | + $this->logger->warn("Failed to clear cache: ".$this->cacheContainer->cachePrefix."*"); |
|
| 160 | 160 | $result = false; |
| 161 | 161 | } |
| 162 | 162 | } else { |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | } else { |
| 172 | - $this->logger->warn("Can't read directory:" . $dir->getFilePath()); |
|
| 172 | + $this->logger->warn("Can't read directory:".$dir->getFilePath()); |
|
| 173 | 173 | $result = false; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WebStream\Cache\Driver; |
| 3 | 3 | |
| 4 | -use WebStream\DI\Injector; |
|
| 5 | 4 | use WebStream\Module\Container; |
| 6 | 5 | |
| 7 | 6 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $driver = $factory->create("WebStream\Cache\Driver\Apcu"); |
| 32 | 32 | break; |
| 33 | 33 | case "memcached": |
| 34 | - $cacheConfig = \Spyc::YAMLLoad($this->getApplicationRoot() . '/config/cache.yml'); |
|
| 34 | + $cacheConfig = \Spyc::YAMLLoad($this->getApplicationRoot().'/config/cache.yml'); |
|
| 35 | 35 | if (array_key_exists('memcached', $cacheConfig)) { |
| 36 | 36 | $config = new Container(false); |
| 37 | 37 | $config->servers = [$cacheConfig['host'], $cacheConfig['port']]; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | break; |
| 41 | 41 | case "redis": |
| 42 | - $cacheConfig = \Spyc::YAMLLoad($this->getApplicationRoot() . '/config/cache.yml'); |
|
| 42 | + $cacheConfig = \Spyc::YAMLLoad($this->getApplicationRoot().'/config/cache.yml'); |
|
| 43 | 43 | if (array_key_exists('redis', $cacheConfig)) { |
| 44 | 44 | $config = new Container(false); |
| 45 | 45 | $config->host = $cacheConfig['host']; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function add(string $content) |
| 52 | 52 | { |
| 53 | - $this->driver->add($this->key . $this->index++, $content); |
|
| 53 | + $this->driver->add($this->key.$this->index++, $content); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $list = []; |
| 63 | 63 | for ($i = 0; $i < $this->index; $i++) { |
| 64 | - $list[] = $this->driver->get($this->key . $i); |
|
| 64 | + $list[] = $this->driver->get($this->key.$i); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return $list; |
@@ -141,7 +141,7 @@ |
||
| 141 | 141 | $cacheContainer->driver->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_IGBINARY); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $cacheContainer->driver->setOption(\Redis::OPT_PREFIX, $container->cachePrefix . '.' . $container->classPrefix); |
|
| 144 | + $cacheContainer->driver->setOption(\Redis::OPT_PREFIX, $container->cachePrefix.'.'.$container->classPrefix); |
|
| 145 | 145 | $cacheContainer->driver->setOption(\Redis::OPT_SCAN, \Redis::SCAN_RETRY); |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | public function __construct(Container $cacheContainer) |
| 31 | 31 | { |
| 32 | 32 | $this->cacheContainer = $cacheContainer; |
| 33 | - $this->cachePrefix = $this->cacheContainer->cachePrefix . '.' . $this->cacheContainer->classPrefix . '.'; |
|
| 33 | + $this->cachePrefix = $this->cacheContainer->cachePrefix.'.'.$this->cacheContainer->classPrefix.'.'; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | if (!$this->isAvailableCacheLibrary()) { |
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | - $key = $this->cachePrefix . $key; |
|
| 44 | + $key = $this->cachePrefix.$key; |
|
| 45 | 45 | $result = null; |
| 46 | 46 | |
| 47 | 47 | if ($ttl > 0) { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $this->logger->info("Execute cache save: " . $key); |
|
| 67 | + $this->logger->info("Execute cache save: ".$key); |
|
| 68 | 68 | $this->verifyReturnCode($this->cacheContainer->codes['success']); |
| 69 | 69 | |
| 70 | 70 | return $result; |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | if (!$this->isAvailableCacheLibrary()) { |
| 79 | 79 | return false; |
| 80 | 80 | } |
| 81 | - $key = $this->cachePrefix . $key; |
|
| 81 | + $key = $this->cachePrefix.$key; |
|
| 82 | 82 | $result = $this->cacheContainer->driver->get($key); |
| 83 | 83 | |
| 84 | 84 | if ($result !== false) { |
| 85 | - $this->logger->info("Execute cache read: " . $key); |
|
| 85 | + $this->logger->info("Execute cache read: ".$key); |
|
| 86 | 86 | } else { |
| 87 | - $this->logger->warn("Failed to read cache: " . $key); |
|
| 87 | + $this->logger->warn("Failed to read cache: ".$key); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return $this->verifyReturnCode($this->cacheContainer->codes['success']) ? $result : null; |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | if (!$this->isAvailableCacheLibrary()) { |
| 99 | 99 | return false; |
| 100 | 100 | } |
| 101 | - $key = $this->cachePrefix . $key; |
|
| 101 | + $key = $this->cachePrefix.$key; |
|
| 102 | 102 | $this->cacheContainer->driver->delete($key); |
| 103 | 103 | |
| 104 | 104 | if ($this->verifyReturnCode($this->cacheContainer->codes['notfound'])) { |
| 105 | - $this->logger->info("Execute cache cleared: " . $key); |
|
| 105 | + $this->logger->info("Execute cache cleared: ".$key); |
|
| 106 | 106 | return true; |
| 107 | 107 | } else { |
| 108 | - $this->logger->warn("Failed to clear cache: " . $key); |
|
| 108 | + $this->logger->warn("Failed to clear cache: ".$key); |
|
| 109 | 109 | return false; |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | $allKeys = $this->cacheContainer->driver->getAllKeys(); |
| 122 | 122 | if ($allKeys === false) { |
| 123 | - $this->logger->warn("Can't get cache keys: " . $this->cachePrefix . "*"); |
|
| 123 | + $this->logger->warn("Can't get cache keys: ".$this->cachePrefix."*"); |
|
| 124 | 124 | $this->cacheContainer->driver->flush(); |
| 125 | 125 | |
| 126 | 126 | return true; |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | $this->cacheContainer->driver->deleteMulti($targetKeys); |
| 138 | 138 | |
| 139 | 139 | if ($this->verifyReturnCode($this->cacheContainer->codes['notfound'])) { |
| 140 | - $this->logger->info("Execute all cache cleared: " . $this->cachePrefix . "*"); |
|
| 140 | + $this->logger->info("Execute all cache cleared: ".$this->cachePrefix."*"); |
|
| 141 | 141 | return true; |
| 142 | 142 | } else { |
| 143 | - $this->logger->warn("Failed to clear all cache: " . $this->cachePrefix . "*"); |
|
| 143 | + $this->logger->warn("Failed to clear all cache: ".$this->cachePrefix."*"); |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | } |