@@ -21,79 +21,79 @@ |
||
21 | 21 | |
22 | 22 | class Config extends ConfigurationOption |
23 | 23 | { |
24 | - protected string $host = '127.0.0.1'; |
|
25 | - protected int $port = 8888; |
|
26 | - protected string $password = ''; |
|
27 | - protected int $timeout = 2000; |
|
24 | + protected string $host = '127.0.0.1'; |
|
25 | + protected int $port = 8888; |
|
26 | + protected string $password = ''; |
|
27 | + protected int $timeout = 2000; |
|
28 | 28 | /** |
29 | - * @return string |
|
30 | - */ |
|
31 | - public function getHost(): string |
|
32 | - { |
|
33 | - return $this->host; |
|
34 | - } |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function getHost(): string |
|
32 | + { |
|
33 | + return $this->host; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $host |
|
38 | - * @return Config |
|
39 | - * @throws PhpfastcacheLogicException |
|
40 | - */ |
|
41 | - public function setHost(string $host): Config |
|
42 | - { |
|
43 | - return $this->setProperty('host', $host); |
|
44 | - } |
|
36 | + /** |
|
37 | + * @param string $host |
|
38 | + * @return Config |
|
39 | + * @throws PhpfastcacheLogicException |
|
40 | + */ |
|
41 | + public function setHost(string $host): Config |
|
42 | + { |
|
43 | + return $this->setProperty('host', $host); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return int |
|
48 | - */ |
|
49 | - public function getPort(): int |
|
50 | - { |
|
51 | - return $this->port; |
|
52 | - } |
|
46 | + /** |
|
47 | + * @return int |
|
48 | + */ |
|
49 | + public function getPort(): int |
|
50 | + { |
|
51 | + return $this->port; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param int $port |
|
56 | - * @return Config |
|
57 | - * @throws PhpfastcacheLogicException |
|
58 | - */ |
|
59 | - public function setPort(int $port): Config |
|
60 | - { |
|
61 | - return $this->setProperty('port', $port); |
|
62 | - } |
|
54 | + /** |
|
55 | + * @param int $port |
|
56 | + * @return Config |
|
57 | + * @throws PhpfastcacheLogicException |
|
58 | + */ |
|
59 | + public function setPort(int $port): Config |
|
60 | + { |
|
61 | + return $this->setProperty('port', $port); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getPassword(): string |
|
68 | - { |
|
69 | - return $this->password; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getPassword(): string |
|
68 | + { |
|
69 | + return $this->password; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param string $password |
|
74 | - * @return Config |
|
75 | - * @throws PhpfastcacheLogicException |
|
76 | - */ |
|
77 | - public function setPassword(string $password): Config |
|
78 | - { |
|
79 | - return $this->setProperty('password', $password); |
|
80 | - } |
|
72 | + /** |
|
73 | + * @param string $password |
|
74 | + * @return Config |
|
75 | + * @throws PhpfastcacheLogicException |
|
76 | + */ |
|
77 | + public function setPassword(string $password): Config |
|
78 | + { |
|
79 | + return $this->setProperty('password', $password); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return int |
|
84 | - */ |
|
85 | - public function getTimeout(): int |
|
86 | - { |
|
87 | - return $this->timeout; |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return int |
|
84 | + */ |
|
85 | + public function getTimeout(): int |
|
86 | + { |
|
87 | + return $this->timeout; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param int $timeout |
|
92 | - * @return Config |
|
93 | - * @throws PhpfastcacheLogicException |
|
94 | - */ |
|
95 | - public function setTimeout(int $timeout): Config |
|
96 | - { |
|
97 | - return $this->setProperty('timeout', $timeout); |
|
98 | - } |
|
90 | + /** |
|
91 | + * @param int $timeout |
|
92 | + * @return Config |
|
93 | + * @throws PhpfastcacheLogicException |
|
94 | + */ |
|
95 | + public function setTimeout(int $timeout): Config |
|
96 | + { |
|
97 | + return $this->setProperty('timeout', $timeout); |
|
98 | + } |
|
99 | 99 | } |
@@ -33,86 +33,86 @@ |
||
33 | 33 | */ |
34 | 34 | class Driver implements AggregatablePoolInterface |
35 | 35 | { |
36 | - use TaggableCacheItemPoolTrait; |
|
37 | - |
|
38 | - /** |
|
39 | - * @return bool |
|
40 | - */ |
|
41 | - public function driverCheck(): bool |
|
42 | - { |
|
43 | - return extension_loaded('apcu') && ((ini_get('apc.enabled') && SapiDetector::isWebScript()) || (ini_get('apc.enable_cli') && SapiDetector::isCliScript())); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @return DriverStatistic |
|
48 | - */ |
|
49 | - public function getStats(): DriverStatistic |
|
50 | - { |
|
51 | - $stats = (array)apcu_cache_info(); |
|
52 | - $date = (new DateTime())->setTimestamp($stats['start_time']); |
|
53 | - |
|
54 | - return (new DriverStatistic()) |
|
55 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
56 | - ->setInfo( |
|
57 | - sprintf( |
|
58 | - "The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", |
|
59 | - $date->format(DATE_RFC2822), |
|
60 | - $stats['num_entries'] |
|
61 | - ) |
|
62 | - ) |
|
63 | - ->setRawData($stats) |
|
64 | - ->setSize((int)$stats['mem_size']); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - protected function driverConnect(): bool |
|
71 | - { |
|
72 | - return true; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param ExtendedCacheItemInterface $item |
|
77 | - * @return bool |
|
78 | - * @throws PhpfastcacheInvalidArgumentException |
|
79 | - */ |
|
80 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
81 | - { |
|
82 | - |
|
83 | - return (bool)apcu_store($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param ExtendedCacheItemInterface $item |
|
88 | - * @return ?array<string, mixed> |
|
89 | - */ |
|
90 | - protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
91 | - { |
|
92 | - $data = apcu_fetch($item->getKey(), $success); |
|
93 | - |
|
94 | - if ($success === false || !\is_array($data)) { |
|
95 | - return null; |
|
96 | - } |
|
97 | - |
|
98 | - return $data; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $key |
|
103 | - * @param string $encodedKey |
|
104 | - * @return bool |
|
105 | - */ |
|
106 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
107 | - { |
|
108 | - return (bool)apcu_delete($key); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return bool |
|
113 | - */ |
|
114 | - protected function driverClear(): bool |
|
115 | - { |
|
116 | - return @apcu_clear_cache(); |
|
117 | - } |
|
36 | + use TaggableCacheItemPoolTrait; |
|
37 | + |
|
38 | + /** |
|
39 | + * @return bool |
|
40 | + */ |
|
41 | + public function driverCheck(): bool |
|
42 | + { |
|
43 | + return extension_loaded('apcu') && ((ini_get('apc.enabled') && SapiDetector::isWebScript()) || (ini_get('apc.enable_cli') && SapiDetector::isCliScript())); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @return DriverStatistic |
|
48 | + */ |
|
49 | + public function getStats(): DriverStatistic |
|
50 | + { |
|
51 | + $stats = (array)apcu_cache_info(); |
|
52 | + $date = (new DateTime())->setTimestamp($stats['start_time']); |
|
53 | + |
|
54 | + return (new DriverStatistic()) |
|
55 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
56 | + ->setInfo( |
|
57 | + sprintf( |
|
58 | + "The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", |
|
59 | + $date->format(DATE_RFC2822), |
|
60 | + $stats['num_entries'] |
|
61 | + ) |
|
62 | + ) |
|
63 | + ->setRawData($stats) |
|
64 | + ->setSize((int)$stats['mem_size']); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + protected function driverConnect(): bool |
|
71 | + { |
|
72 | + return true; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param ExtendedCacheItemInterface $item |
|
77 | + * @return bool |
|
78 | + * @throws PhpfastcacheInvalidArgumentException |
|
79 | + */ |
|
80 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
81 | + { |
|
82 | + |
|
83 | + return (bool)apcu_store($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param ExtendedCacheItemInterface $item |
|
88 | + * @return ?array<string, mixed> |
|
89 | + */ |
|
90 | + protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
91 | + { |
|
92 | + $data = apcu_fetch($item->getKey(), $success); |
|
93 | + |
|
94 | + if ($success === false || !\is_array($data)) { |
|
95 | + return null; |
|
96 | + } |
|
97 | + |
|
98 | + return $data; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $key |
|
103 | + * @param string $encodedKey |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
107 | + { |
|
108 | + return (bool)apcu_delete($key); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return bool |
|
113 | + */ |
|
114 | + protected function driverClear(): bool |
|
115 | + { |
|
116 | + return @apcu_clear_cache(); |
|
117 | + } |
|
118 | 118 | } |
@@ -36,72 +36,72 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class Driver implements AggregatablePoolInterface |
38 | 38 | { |
39 | - use TaggableCacheItemPoolTrait; |
|
40 | - |
|
41 | - protected const CASSANDRA_KEY_SPACE = 'phpfastcache'; |
|
42 | - protected const CASSANDRA_TABLE = 'cacheItems'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @return bool |
|
46 | - */ |
|
47 | - public function driverCheck(): bool |
|
48 | - { |
|
49 | - return extension_loaded('Cassandra') && class_exists(Cassandra::class); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return bool |
|
54 | - * @throws PhpfastcacheLogicException |
|
55 | - * @throws Exception |
|
56 | - */ |
|
57 | - protected function driverConnect(): bool |
|
58 | - { |
|
59 | - $clientConfig = $this->getConfig(); |
|
60 | - |
|
61 | - $clusterBuilder = Cassandra::cluster() |
|
62 | - ->withContactPoints($clientConfig->getHost()) |
|
63 | - ->withPort($clientConfig->getPort()); |
|
64 | - |
|
65 | - if (!empty($clientConfig->isSslEnabled())) { |
|
66 | - $sslBuilder = Cassandra::ssl(); |
|
67 | - if (!empty($clientConfig->isSslVerify())) { |
|
68 | - $sslBuilder->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); |
|
69 | - } else { |
|
70 | - $sslBuilder->withVerifyFlags(Cassandra::VERIFY_NONE); |
|
71 | - } |
|
72 | - |
|
73 | - $clusterBuilder->withSSL($sslBuilder->build()); |
|
74 | - } |
|
75 | - |
|
76 | - $clusterBuilder->withConnectTimeout($clientConfig->getTimeout()); |
|
77 | - |
|
78 | - if ($clientConfig->getUsername()) { |
|
79 | - $clusterBuilder->withCredentials($clientConfig->getUsername(), $clientConfig->getPassword()); |
|
80 | - } |
|
81 | - |
|
82 | - $this->instance = $clusterBuilder->build()->connect(''); |
|
83 | - |
|
84 | - /** |
|
85 | - * In case of emergency: |
|
86 | - * $this->instance->execute( |
|
87 | - * new Cassandra\SimpleStatement(\sprintf("DROP KEYSPACE %s;", self::CASSANDRA_KEY_SPACE)) |
|
88 | - * ); |
|
89 | - */ |
|
90 | - |
|
91 | - $this->instance->execute( |
|
92 | - new Cassandra\SimpleStatement( |
|
93 | - sprintf( |
|
94 | - "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", |
|
95 | - self::CASSANDRA_KEY_SPACE |
|
96 | - ) |
|
97 | - ), |
|
98 | - [] |
|
99 | - ); |
|
100 | - $this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE)), []); |
|
101 | - $this->instance->execute( |
|
102 | - new Cassandra\SimpleStatement( |
|
103 | - sprintf( |
|
104 | - ' |
|
39 | + use TaggableCacheItemPoolTrait; |
|
40 | + |
|
41 | + protected const CASSANDRA_KEY_SPACE = 'phpfastcache'; |
|
42 | + protected const CASSANDRA_TABLE = 'cacheItems'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + public function driverCheck(): bool |
|
48 | + { |
|
49 | + return extension_loaded('Cassandra') && class_exists(Cassandra::class); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return bool |
|
54 | + * @throws PhpfastcacheLogicException |
|
55 | + * @throws Exception |
|
56 | + */ |
|
57 | + protected function driverConnect(): bool |
|
58 | + { |
|
59 | + $clientConfig = $this->getConfig(); |
|
60 | + |
|
61 | + $clusterBuilder = Cassandra::cluster() |
|
62 | + ->withContactPoints($clientConfig->getHost()) |
|
63 | + ->withPort($clientConfig->getPort()); |
|
64 | + |
|
65 | + if (!empty($clientConfig->isSslEnabled())) { |
|
66 | + $sslBuilder = Cassandra::ssl(); |
|
67 | + if (!empty($clientConfig->isSslVerify())) { |
|
68 | + $sslBuilder->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); |
|
69 | + } else { |
|
70 | + $sslBuilder->withVerifyFlags(Cassandra::VERIFY_NONE); |
|
71 | + } |
|
72 | + |
|
73 | + $clusterBuilder->withSSL($sslBuilder->build()); |
|
74 | + } |
|
75 | + |
|
76 | + $clusterBuilder->withConnectTimeout($clientConfig->getTimeout()); |
|
77 | + |
|
78 | + if ($clientConfig->getUsername()) { |
|
79 | + $clusterBuilder->withCredentials($clientConfig->getUsername(), $clientConfig->getPassword()); |
|
80 | + } |
|
81 | + |
|
82 | + $this->instance = $clusterBuilder->build()->connect(''); |
|
83 | + |
|
84 | + /** |
|
85 | + * In case of emergency: |
|
86 | + * $this->instance->execute( |
|
87 | + * new Cassandra\SimpleStatement(\sprintf("DROP KEYSPACE %s;", self::CASSANDRA_KEY_SPACE)) |
|
88 | + * ); |
|
89 | + */ |
|
90 | + |
|
91 | + $this->instance->execute( |
|
92 | + new Cassandra\SimpleStatement( |
|
93 | + sprintf( |
|
94 | + "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", |
|
95 | + self::CASSANDRA_KEY_SPACE |
|
96 | + ) |
|
97 | + ), |
|
98 | + [] |
|
99 | + ); |
|
100 | + $this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE)), []); |
|
101 | + $this->instance->execute( |
|
102 | + new Cassandra\SimpleStatement( |
|
103 | + sprintf( |
|
104 | + ' |
|
105 | 105 | CREATE TABLE IF NOT EXISTS %s ( |
106 | 106 | cache_uuid uuid, |
107 | 107 | cache_id varchar, |
@@ -111,72 +111,72 @@ discard block |
||
111 | 111 | cache_length int, |
112 | 112 | PRIMARY KEY (cache_id) |
113 | 113 | );', |
114 | - self::CASSANDRA_TABLE |
|
115 | - ) |
|
116 | - ), |
|
117 | - [] |
|
118 | - ); |
|
119 | - |
|
120 | - return true; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param ExtendedCacheItemInterface $item |
|
125 | - * @return ?array<string, mixed> |
|
126 | - */ |
|
127 | - protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
128 | - { |
|
129 | - try { |
|
130 | - $options = $this->getCompatibleExecutionOptionsArgument( |
|
131 | - [ |
|
132 | - 'arguments' => ['cache_id' => $item->getKey()], |
|
133 | - 'page_size' => 1, |
|
134 | - ] |
|
135 | - ); |
|
136 | - $query = sprintf( |
|
137 | - 'SELECT cache_data FROM %s.%s WHERE cache_id = :cache_id;', |
|
138 | - self::CASSANDRA_KEY_SPACE, |
|
139 | - self::CASSANDRA_TABLE |
|
140 | - ); |
|
141 | - $results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
142 | - |
|
143 | - if ($results instanceof Cassandra\Rows && $results->count() === 1) { |
|
144 | - return $this->decode($results->first()['cache_data']) ?: null; |
|
145 | - } |
|
146 | - |
|
147 | - return null; |
|
148 | - } catch (Exception $e) { |
|
149 | - return null; |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param ExtendedCacheItemInterface $item |
|
155 | - * @return bool |
|
156 | - * @throws PhpfastcacheInvalidArgumentException |
|
157 | - */ |
|
158 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
159 | - { |
|
160 | - |
|
161 | - try { |
|
162 | - $cacheData = $this->encode($this->driverPreWrap($item)); |
|
163 | - $options = $this->getCompatibleExecutionOptionsArgument( |
|
164 | - [ |
|
165 | - 'arguments' => [ |
|
166 | - 'cache_uuid' => new Cassandra\Uuid(''), |
|
167 | - 'cache_id' => $item->getKey(), |
|
168 | - 'cache_data' => $cacheData, |
|
169 | - 'cache_creation_date' => new Cassandra\Timestamp((new DateTime())->getTimestamp(), 0), |
|
170 | - 'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp(), 0), |
|
171 | - 'cache_length' => strlen($cacheData), |
|
172 | - ], |
|
173 | - 'consistency' => Cassandra::CONSISTENCY_ALL, |
|
174 | - 'serial_consistency' => Cassandra::CONSISTENCY_SERIAL, |
|
175 | - ] |
|
176 | - ); |
|
177 | - |
|
178 | - $query = sprintf( |
|
179 | - 'INSERT INTO %s.%s |
|
114 | + self::CASSANDRA_TABLE |
|
115 | + ) |
|
116 | + ), |
|
117 | + [] |
|
118 | + ); |
|
119 | + |
|
120 | + return true; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param ExtendedCacheItemInterface $item |
|
125 | + * @return ?array<string, mixed> |
|
126 | + */ |
|
127 | + protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
128 | + { |
|
129 | + try { |
|
130 | + $options = $this->getCompatibleExecutionOptionsArgument( |
|
131 | + [ |
|
132 | + 'arguments' => ['cache_id' => $item->getKey()], |
|
133 | + 'page_size' => 1, |
|
134 | + ] |
|
135 | + ); |
|
136 | + $query = sprintf( |
|
137 | + 'SELECT cache_data FROM %s.%s WHERE cache_id = :cache_id;', |
|
138 | + self::CASSANDRA_KEY_SPACE, |
|
139 | + self::CASSANDRA_TABLE |
|
140 | + ); |
|
141 | + $results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
142 | + |
|
143 | + if ($results instanceof Cassandra\Rows && $results->count() === 1) { |
|
144 | + return $this->decode($results->first()['cache_data']) ?: null; |
|
145 | + } |
|
146 | + |
|
147 | + return null; |
|
148 | + } catch (Exception $e) { |
|
149 | + return null; |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param ExtendedCacheItemInterface $item |
|
155 | + * @return bool |
|
156 | + * @throws PhpfastcacheInvalidArgumentException |
|
157 | + */ |
|
158 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
159 | + { |
|
160 | + |
|
161 | + try { |
|
162 | + $cacheData = $this->encode($this->driverPreWrap($item)); |
|
163 | + $options = $this->getCompatibleExecutionOptionsArgument( |
|
164 | + [ |
|
165 | + 'arguments' => [ |
|
166 | + 'cache_uuid' => new Cassandra\Uuid(''), |
|
167 | + 'cache_id' => $item->getKey(), |
|
168 | + 'cache_data' => $cacheData, |
|
169 | + 'cache_creation_date' => new Cassandra\Timestamp((new DateTime())->getTimestamp(), 0), |
|
170 | + 'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp(), 0), |
|
171 | + 'cache_length' => strlen($cacheData), |
|
172 | + ], |
|
173 | + 'consistency' => Cassandra::CONSISTENCY_ALL, |
|
174 | + 'serial_consistency' => Cassandra::CONSISTENCY_SERIAL, |
|
175 | + ] |
|
176 | + ); |
|
177 | + |
|
178 | + $query = sprintf( |
|
179 | + 'INSERT INTO %s.%s |
|
180 | 180 | ( |
181 | 181 | cache_uuid, |
182 | 182 | cache_id, |
@@ -187,89 +187,89 @@ discard block |
||
187 | 187 | ) |
188 | 188 | VALUES (:cache_uuid, :cache_id, :cache_data, :cache_creation_date, :cache_expiration_date, :cache_length); |
189 | 189 | ', |
190 | - self::CASSANDRA_KEY_SPACE, |
|
191 | - self::CASSANDRA_TABLE |
|
192 | - ); |
|
193 | - |
|
194 | - $result = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
195 | - /** |
|
196 | - * There's no real way atm |
|
197 | - * to know if the item has |
|
198 | - * been really upserted |
|
199 | - */ |
|
200 | - return $result instanceof Cassandra\Rows; |
|
201 | - } catch (InvalidArgumentException $e) { |
|
202 | - throw new PhpfastcacheInvalidArgumentException($e->getMessage(), 0, $e); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param string $key |
|
208 | - * @param string $encodedKey |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
212 | - { |
|
213 | - |
|
214 | - try { |
|
215 | - $options = $this->getCompatibleExecutionOptionsArgument( |
|
216 | - [ |
|
217 | - 'arguments' => [ |
|
218 | - 'cache_id' => $key, |
|
219 | - ], |
|
220 | - ] |
|
221 | - ); |
|
222 | - $result = $this->instance->execute( |
|
223 | - new Cassandra\SimpleStatement( |
|
224 | - sprintf( |
|
225 | - 'DELETE FROM %s.%s WHERE cache_id = :cache_id;', |
|
226 | - self::CASSANDRA_KEY_SPACE, |
|
227 | - self::CASSANDRA_TABLE |
|
228 | - ) |
|
229 | - ), |
|
230 | - $options |
|
231 | - ); |
|
232 | - |
|
233 | - /** |
|
234 | - * There's no real way atm |
|
235 | - * to know if the item has |
|
236 | - * been really deleted |
|
237 | - */ |
|
238 | - return $result instanceof Cassandra\Rows; |
|
239 | - } catch (Exception $e) { |
|
240 | - return false; |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @return bool |
|
246 | - */ |
|
247 | - protected function driverClear(): bool |
|
248 | - { |
|
249 | - try { |
|
250 | - $this->instance->execute( |
|
251 | - new Cassandra\SimpleStatement( |
|
252 | - sprintf( |
|
253 | - 'TRUNCATE %s.%s;', |
|
254 | - self::CASSANDRA_KEY_SPACE, |
|
255 | - self::CASSANDRA_TABLE |
|
256 | - ) |
|
257 | - ), |
|
258 | - null |
|
259 | - ); |
|
260 | - |
|
261 | - return true; |
|
262 | - } catch (Exception) { |
|
263 | - return false; |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function getHelp(): string |
|
271 | - { |
|
272 | - return <<<HELP |
|
190 | + self::CASSANDRA_KEY_SPACE, |
|
191 | + self::CASSANDRA_TABLE |
|
192 | + ); |
|
193 | + |
|
194 | + $result = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
195 | + /** |
|
196 | + * There's no real way atm |
|
197 | + * to know if the item has |
|
198 | + * been really upserted |
|
199 | + */ |
|
200 | + return $result instanceof Cassandra\Rows; |
|
201 | + } catch (InvalidArgumentException $e) { |
|
202 | + throw new PhpfastcacheInvalidArgumentException($e->getMessage(), 0, $e); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param string $key |
|
208 | + * @param string $encodedKey |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
212 | + { |
|
213 | + |
|
214 | + try { |
|
215 | + $options = $this->getCompatibleExecutionOptionsArgument( |
|
216 | + [ |
|
217 | + 'arguments' => [ |
|
218 | + 'cache_id' => $key, |
|
219 | + ], |
|
220 | + ] |
|
221 | + ); |
|
222 | + $result = $this->instance->execute( |
|
223 | + new Cassandra\SimpleStatement( |
|
224 | + sprintf( |
|
225 | + 'DELETE FROM %s.%s WHERE cache_id = :cache_id;', |
|
226 | + self::CASSANDRA_KEY_SPACE, |
|
227 | + self::CASSANDRA_TABLE |
|
228 | + ) |
|
229 | + ), |
|
230 | + $options |
|
231 | + ); |
|
232 | + |
|
233 | + /** |
|
234 | + * There's no real way atm |
|
235 | + * to know if the item has |
|
236 | + * been really deleted |
|
237 | + */ |
|
238 | + return $result instanceof Cassandra\Rows; |
|
239 | + } catch (Exception $e) { |
|
240 | + return false; |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @return bool |
|
246 | + */ |
|
247 | + protected function driverClear(): bool |
|
248 | + { |
|
249 | + try { |
|
250 | + $this->instance->execute( |
|
251 | + new Cassandra\SimpleStatement( |
|
252 | + sprintf( |
|
253 | + 'TRUNCATE %s.%s;', |
|
254 | + self::CASSANDRA_KEY_SPACE, |
|
255 | + self::CASSANDRA_TABLE |
|
256 | + ) |
|
257 | + ), |
|
258 | + null |
|
259 | + ); |
|
260 | + |
|
261 | + return true; |
|
262 | + } catch (Exception) { |
|
263 | + return false; |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function getHelp(): string |
|
271 | + { |
|
272 | + return <<<HELP |
|
273 | 273 | <p> |
274 | 274 | To install the php Cassandra extension via Pecl: |
275 | 275 | <code>sudo pecl install cassandra</code> |
@@ -277,42 +277,42 @@ discard block |
||
277 | 277 | Please note that this repository only provide php stubs and C/C++ sources, it does NOT provide php client. |
278 | 278 | </p> |
279 | 279 | HELP; |
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @return DriverStatistic |
|
284 | - * @throws Exception |
|
285 | - */ |
|
286 | - public function getStats(): DriverStatistic |
|
287 | - { |
|
288 | - $result = $this->instance->execute( |
|
289 | - new Cassandra\SimpleStatement( |
|
290 | - sprintf( |
|
291 | - 'SELECT SUM(cache_length) as cache_size FROM %s.%s', |
|
292 | - self::CASSANDRA_KEY_SPACE, |
|
293 | - self::CASSANDRA_TABLE |
|
294 | - ) |
|
295 | - ), |
|
296 | - null |
|
297 | - ); |
|
298 | - |
|
299 | - return (new DriverStatistic()) |
|
300 | - ->setSize($result->first()['cache_size']) |
|
301 | - ->setRawData([]) |
|
302 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
303 | - ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * @param array<string, mixed> $options |
|
308 | - * @return array<string, mixed>|Cassandra\ExecutionOptions |
|
309 | - */ |
|
310 | - protected function getCompatibleExecutionOptionsArgument(array $options): mixed |
|
311 | - { |
|
312 | - if ($this->getConfig()->isUseLegacyExecutionOptions()) { |
|
313 | - return new Cassandra\ExecutionOptions($options); |
|
314 | - } |
|
315 | - |
|
316 | - return $options; |
|
317 | - } |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @return DriverStatistic |
|
284 | + * @throws Exception |
|
285 | + */ |
|
286 | + public function getStats(): DriverStatistic |
|
287 | + { |
|
288 | + $result = $this->instance->execute( |
|
289 | + new Cassandra\SimpleStatement( |
|
290 | + sprintf( |
|
291 | + 'SELECT SUM(cache_length) as cache_size FROM %s.%s', |
|
292 | + self::CASSANDRA_KEY_SPACE, |
|
293 | + self::CASSANDRA_TABLE |
|
294 | + ) |
|
295 | + ), |
|
296 | + null |
|
297 | + ); |
|
298 | + |
|
299 | + return (new DriverStatistic()) |
|
300 | + ->setSize($result->first()['cache_size']) |
|
301 | + ->setRawData([]) |
|
302 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
303 | + ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * @param array<string, mixed> $options |
|
308 | + * @return array<string, mixed>|Cassandra\ExecutionOptions |
|
309 | + */ |
|
310 | + protected function getCompatibleExecutionOptionsArgument(array $options): mixed |
|
311 | + { |
|
312 | + if ($this->getConfig()->isUseLegacyExecutionOptions()) { |
|
313 | + return new Cassandra\ExecutionOptions($options); |
|
314 | + } |
|
315 | + |
|
316 | + return $options; |
|
317 | + } |
|
318 | 318 | } |
@@ -21,152 +21,152 @@ |
||
21 | 21 | |
22 | 22 | class Config extends ConfigurationOption |
23 | 23 | { |
24 | - protected string $host = '127.0.0.1'; |
|
25 | - |
|
26 | - protected int $port = 9042; |
|
27 | - |
|
28 | - protected int $timeout = 2; |
|
29 | - |
|
30 | - protected string $username = ''; |
|
31 | - |
|
32 | - protected string $password = ''; |
|
33 | - |
|
34 | - protected bool $sslEnabled = false; |
|
35 | - |
|
36 | - protected bool $sslVerify = false; |
|
37 | - |
|
38 | - protected bool $useLegacyExecutionOptions = false; |
|
39 | - |
|
40 | - public function getHost(): string |
|
41 | - { |
|
42 | - return $this->host; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param string $host |
|
47 | - * @throws PhpfastcacheLogicException |
|
48 | - */ |
|
49 | - public function setHost(string $host): static |
|
50 | - { |
|
51 | - return $this->setProperty('host', $host); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - public function getPort(): int |
|
58 | - { |
|
59 | - return $this->port; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param int $port |
|
64 | - * @throws PhpfastcacheLogicException |
|
65 | - */ |
|
66 | - public function setPort(int $port): static |
|
67 | - { |
|
68 | - return $this->setProperty('port', $port); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return int |
|
73 | - */ |
|
74 | - public function getTimeout(): int |
|
75 | - { |
|
76 | - return $this->timeout; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param int $timeout |
|
81 | - * @throws PhpfastcacheLogicException |
|
82 | - */ |
|
83 | - public function setTimeout(int $timeout): static |
|
84 | - { |
|
85 | - return $this->setProperty('timeout', $timeout); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getUsername(): string |
|
92 | - { |
|
93 | - return $this->username; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $username |
|
98 | - * @throws PhpfastcacheLogicException |
|
99 | - */ |
|
100 | - public function setUsername(string $username): static |
|
101 | - { |
|
102 | - return $this->setProperty('username', $username); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function getPassword(): string |
|
109 | - { |
|
110 | - return $this->password; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $password |
|
115 | - * @throws PhpfastcacheLogicException |
|
116 | - */ |
|
117 | - public function setPassword(string $password): static |
|
118 | - { |
|
119 | - return $this->setProperty('password', $password); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return bool |
|
124 | - */ |
|
125 | - public function isSslEnabled(): bool |
|
126 | - { |
|
127 | - return $this->sslEnabled; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param bool $sslEnabled |
|
132 | - * @throws PhpfastcacheLogicException |
|
133 | - */ |
|
134 | - public function setSslEnabled(bool $sslEnabled): static |
|
135 | - { |
|
136 | - return $this->setProperty('sslEnabled', $sslEnabled); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return bool |
|
141 | - */ |
|
142 | - public function isSslVerify(): bool |
|
143 | - { |
|
144 | - return $this->sslVerify; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param bool $sslVerify |
|
149 | - * @throws PhpfastcacheLogicException |
|
150 | - */ |
|
151 | - public function setSslVerify(bool $sslVerify): static |
|
152 | - { |
|
153 | - return $this->setProperty('sslVerify', $sslVerify); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @return bool |
|
158 | - */ |
|
159 | - public function isUseLegacyExecutionOptions(): bool |
|
160 | - { |
|
161 | - return $this->useLegacyExecutionOptions; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param bool $useLegacyExecutionOptions |
|
166 | - * @throws PhpfastcacheLogicException |
|
167 | - */ |
|
168 | - public function setUseLegacyExecutionOptions(bool $useLegacyExecutionOptions): static |
|
169 | - { |
|
170 | - return $this->setProperty('useLegacyExecutionOptions', $useLegacyExecutionOptions); |
|
171 | - } |
|
24 | + protected string $host = '127.0.0.1'; |
|
25 | + |
|
26 | + protected int $port = 9042; |
|
27 | + |
|
28 | + protected int $timeout = 2; |
|
29 | + |
|
30 | + protected string $username = ''; |
|
31 | + |
|
32 | + protected string $password = ''; |
|
33 | + |
|
34 | + protected bool $sslEnabled = false; |
|
35 | + |
|
36 | + protected bool $sslVerify = false; |
|
37 | + |
|
38 | + protected bool $useLegacyExecutionOptions = false; |
|
39 | + |
|
40 | + public function getHost(): string |
|
41 | + { |
|
42 | + return $this->host; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param string $host |
|
47 | + * @throws PhpfastcacheLogicException |
|
48 | + */ |
|
49 | + public function setHost(string $host): static |
|
50 | + { |
|
51 | + return $this->setProperty('host', $host); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + public function getPort(): int |
|
58 | + { |
|
59 | + return $this->port; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param int $port |
|
64 | + * @throws PhpfastcacheLogicException |
|
65 | + */ |
|
66 | + public function setPort(int $port): static |
|
67 | + { |
|
68 | + return $this->setProperty('port', $port); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return int |
|
73 | + */ |
|
74 | + public function getTimeout(): int |
|
75 | + { |
|
76 | + return $this->timeout; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param int $timeout |
|
81 | + * @throws PhpfastcacheLogicException |
|
82 | + */ |
|
83 | + public function setTimeout(int $timeout): static |
|
84 | + { |
|
85 | + return $this->setProperty('timeout', $timeout); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getUsername(): string |
|
92 | + { |
|
93 | + return $this->username; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $username |
|
98 | + * @throws PhpfastcacheLogicException |
|
99 | + */ |
|
100 | + public function setUsername(string $username): static |
|
101 | + { |
|
102 | + return $this->setProperty('username', $username); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function getPassword(): string |
|
109 | + { |
|
110 | + return $this->password; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $password |
|
115 | + * @throws PhpfastcacheLogicException |
|
116 | + */ |
|
117 | + public function setPassword(string $password): static |
|
118 | + { |
|
119 | + return $this->setProperty('password', $password); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return bool |
|
124 | + */ |
|
125 | + public function isSslEnabled(): bool |
|
126 | + { |
|
127 | + return $this->sslEnabled; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @param bool $sslEnabled |
|
132 | + * @throws PhpfastcacheLogicException |
|
133 | + */ |
|
134 | + public function setSslEnabled(bool $sslEnabled): static |
|
135 | + { |
|
136 | + return $this->setProperty('sslEnabled', $sslEnabled); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return bool |
|
141 | + */ |
|
142 | + public function isSslVerify(): bool |
|
143 | + { |
|
144 | + return $this->sslVerify; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param bool $sslVerify |
|
149 | + * @throws PhpfastcacheLogicException |
|
150 | + */ |
|
151 | + public function setSslVerify(bool $sslVerify): static |
|
152 | + { |
|
153 | + return $this->setProperty('sslVerify', $sslVerify); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @return bool |
|
158 | + */ |
|
159 | + public function isUseLegacyExecutionOptions(): bool |
|
160 | + { |
|
161 | + return $this->useLegacyExecutionOptions; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param bool $useLegacyExecutionOptions |
|
166 | + * @throws PhpfastcacheLogicException |
|
167 | + */ |
|
168 | + public function setUseLegacyExecutionOptions(bool $useLegacyExecutionOptions): static |
|
169 | + { |
|
170 | + return $this->setProperty('useLegacyExecutionOptions', $useLegacyExecutionOptions); |
|
171 | + } |
|
172 | 172 | } |
@@ -29,92 +29,92 @@ |
||
29 | 29 | */ |
30 | 30 | class Driver implements AggregatablePoolInterface |
31 | 31 | { |
32 | - use TaggableCacheItemPoolTrait; |
|
33 | - |
|
34 | - /** |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - public function driverCheck(): bool |
|
38 | - { |
|
39 | - return extension_loaded('Zend Data Cache') && function_exists('zend_disk_cache_store'); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function getHelp(): string |
|
46 | - { |
|
47 | - return <<<HELP |
|
32 | + use TaggableCacheItemPoolTrait; |
|
33 | + |
|
34 | + /** |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + public function driverCheck(): bool |
|
38 | + { |
|
39 | + return extension_loaded('Zend Data Cache') && function_exists('zend_disk_cache_store'); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function getHelp(): string |
|
46 | + { |
|
47 | + return <<<HELP |
|
48 | 48 | <p> |
49 | 49 | This driver rely on Zend Server 8.5+, see: https://www.zend.com/products/zend-server |
50 | 50 | </p> |
51 | 51 | HELP; |
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @return DriverStatistic |
|
56 | - */ |
|
57 | - public function getStats(): DriverStatistic |
|
58 | - { |
|
59 | - $stat = new DriverStatistic(); |
|
60 | - $stat->setInfo('[ZendDisk] A void info string') |
|
61 | - ->setSize(0) |
|
62 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
63 | - ->setRawData(false); |
|
64 | - |
|
65 | - return $stat; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - protected function driverConnect(): bool |
|
72 | - { |
|
73 | - return true; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param ExtendedCacheItemInterface $item |
|
78 | - * @return ?array<string, mixed> |
|
79 | - */ |
|
80 | - protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
81 | - { |
|
82 | - $data = zend_disk_cache_fetch($item->getKey()); |
|
83 | - |
|
84 | - if (empty($data) || !\is_array($data)) { |
|
85 | - return null; |
|
86 | - } |
|
87 | - |
|
88 | - return $data; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param ExtendedCacheItemInterface $item |
|
93 | - * @return mixed |
|
94 | - * @throws PhpfastcacheInvalidArgumentException |
|
95 | - */ |
|
96 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
97 | - { |
|
98 | - |
|
99 | - $ttl = $item->getExpirationDate()->getTimestamp() - time(); |
|
100 | - |
|
101 | - return zend_disk_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @param string $key |
|
106 | - * @param string $encodedKey |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
110 | - { |
|
111 | - |
|
112 | - return (bool)zend_disk_cache_delete($key); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - protected function driverClear(): bool |
|
117 | - { |
|
118 | - return @zend_disk_cache_clear(); |
|
119 | - } |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @return DriverStatistic |
|
56 | + */ |
|
57 | + public function getStats(): DriverStatistic |
|
58 | + { |
|
59 | + $stat = new DriverStatistic(); |
|
60 | + $stat->setInfo('[ZendDisk] A void info string') |
|
61 | + ->setSize(0) |
|
62 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
63 | + ->setRawData(false); |
|
64 | + |
|
65 | + return $stat; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + protected function driverConnect(): bool |
|
72 | + { |
|
73 | + return true; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param ExtendedCacheItemInterface $item |
|
78 | + * @return ?array<string, mixed> |
|
79 | + */ |
|
80 | + protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
81 | + { |
|
82 | + $data = zend_disk_cache_fetch($item->getKey()); |
|
83 | + |
|
84 | + if (empty($data) || !\is_array($data)) { |
|
85 | + return null; |
|
86 | + } |
|
87 | + |
|
88 | + return $data; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param ExtendedCacheItemInterface $item |
|
93 | + * @return mixed |
|
94 | + * @throws PhpfastcacheInvalidArgumentException |
|
95 | + */ |
|
96 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
97 | + { |
|
98 | + |
|
99 | + $ttl = $item->getExpirationDate()->getTimestamp() - time(); |
|
100 | + |
|
101 | + return zend_disk_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @param string $key |
|
106 | + * @param string $encodedKey |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
110 | + { |
|
111 | + |
|
112 | + return (bool)zend_disk_cache_delete($key); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + protected function driverClear(): bool |
|
117 | + { |
|
118 | + return @zend_disk_cache_clear(); |
|
119 | + } |
|
120 | 120 | } |
@@ -32,104 +32,104 @@ |
||
32 | 32 | */ |
33 | 33 | class Driver implements AggregatablePoolInterface |
34 | 34 | { |
35 | - use IOHelperTrait; |
|
36 | - |
|
37 | - protected const LEVELDB_FILENAME = '.database'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @return bool |
|
41 | - */ |
|
42 | - public function driverCheck(): bool |
|
43 | - { |
|
44 | - return extension_loaded('Leveldb'); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Close connection on destruct |
|
49 | - */ |
|
50 | - public function __destruct() |
|
51 | - { |
|
52 | - if ($this->instance instanceof LeveldbClient) { |
|
53 | - $this->instance->close(); |
|
54 | - $this->instance = null; |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param ExtendedCacheItemInterface $item |
|
60 | - * @return ?array<string, mixed> |
|
61 | - */ |
|
62 | - protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
63 | - { |
|
64 | - $val = $this->instance->get($item->getKey()); |
|
65 | - if (!$val) { |
|
66 | - return null; |
|
67 | - } |
|
68 | - |
|
69 | - return $this->decode($val); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param ExtendedCacheItemInterface $item |
|
74 | - * @return bool |
|
75 | - * @throws PhpfastcacheInvalidArgumentException |
|
76 | - * @throws PhpfastcacheLogicException |
|
77 | - */ |
|
78 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
79 | - { |
|
80 | - |
|
81 | - return (bool)$this->instance->set($item->getKey(), $this->encode($this->driverPreWrap($item))); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $key |
|
86 | - * @param string $encodedKey |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
90 | - { |
|
91 | - return $this->instance->delete($key); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @return bool |
|
96 | - * @throws PhpfastcacheCoreException |
|
97 | - * @throws PhpfastcacheLogicException |
|
98 | - */ |
|
99 | - protected function driverClear(): bool |
|
100 | - { |
|
101 | - if ($this->instance instanceof LeveldbClient) { |
|
102 | - $this->instance->close(); |
|
103 | - $this->instance = null; |
|
104 | - } |
|
105 | - $result = LeveldbClient::destroy($this->getLeveldbFile()); |
|
106 | - $this->driverConnect(); |
|
107 | - |
|
108 | - return $result; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return string |
|
113 | - * @throws PhpfastcacheCoreException |
|
114 | - */ |
|
115 | - public function getLeveldbFile(): string |
|
116 | - { |
|
117 | - return $this->getPath() . '/' . self::LEVELDB_FILENAME; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return bool |
|
122 | - * @throws PhpfastcacheCoreException |
|
123 | - * @throws PhpfastcacheLogicException |
|
124 | - */ |
|
125 | - protected function driverConnect(): bool |
|
126 | - { |
|
127 | - if ($this->instance instanceof LeveldbClient) { |
|
128 | - throw new PhpfastcacheLogicException('Already connected to Leveldb database'); |
|
129 | - } |
|
130 | - |
|
131 | - $this->instance = new LeveldbClient($this->getLeveldbFile()); |
|
132 | - |
|
133 | - return true; |
|
134 | - } |
|
35 | + use IOHelperTrait; |
|
36 | + |
|
37 | + protected const LEVELDB_FILENAME = '.database'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @return bool |
|
41 | + */ |
|
42 | + public function driverCheck(): bool |
|
43 | + { |
|
44 | + return extension_loaded('Leveldb'); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Close connection on destruct |
|
49 | + */ |
|
50 | + public function __destruct() |
|
51 | + { |
|
52 | + if ($this->instance instanceof LeveldbClient) { |
|
53 | + $this->instance->close(); |
|
54 | + $this->instance = null; |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param ExtendedCacheItemInterface $item |
|
60 | + * @return ?array<string, mixed> |
|
61 | + */ |
|
62 | + protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
63 | + { |
|
64 | + $val = $this->instance->get($item->getKey()); |
|
65 | + if (!$val) { |
|
66 | + return null; |
|
67 | + } |
|
68 | + |
|
69 | + return $this->decode($val); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param ExtendedCacheItemInterface $item |
|
74 | + * @return bool |
|
75 | + * @throws PhpfastcacheInvalidArgumentException |
|
76 | + * @throws PhpfastcacheLogicException |
|
77 | + */ |
|
78 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
79 | + { |
|
80 | + |
|
81 | + return (bool)$this->instance->set($item->getKey(), $this->encode($this->driverPreWrap($item))); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $key |
|
86 | + * @param string $encodedKey |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
90 | + { |
|
91 | + return $this->instance->delete($key); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @return bool |
|
96 | + * @throws PhpfastcacheCoreException |
|
97 | + * @throws PhpfastcacheLogicException |
|
98 | + */ |
|
99 | + protected function driverClear(): bool |
|
100 | + { |
|
101 | + if ($this->instance instanceof LeveldbClient) { |
|
102 | + $this->instance->close(); |
|
103 | + $this->instance = null; |
|
104 | + } |
|
105 | + $result = LeveldbClient::destroy($this->getLeveldbFile()); |
|
106 | + $this->driverConnect(); |
|
107 | + |
|
108 | + return $result; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return string |
|
113 | + * @throws PhpfastcacheCoreException |
|
114 | + */ |
|
115 | + public function getLeveldbFile(): string |
|
116 | + { |
|
117 | + return $this->getPath() . '/' . self::LEVELDB_FILENAME; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return bool |
|
122 | + * @throws PhpfastcacheCoreException |
|
123 | + * @throws PhpfastcacheLogicException |
|
124 | + */ |
|
125 | + protected function driverConnect(): bool |
|
126 | + { |
|
127 | + if ($this->instance instanceof LeveldbClient) { |
|
128 | + throw new PhpfastcacheLogicException('Already connected to Leveldb database'); |
|
129 | + } |
|
130 | + |
|
131 | + $this->instance = new LeveldbClient($this->getLeveldbFile()); |
|
132 | + |
|
133 | + return true; |
|
134 | + } |
|
135 | 135 | } |
@@ -25,9 +25,9 @@ |
||
25 | 25 | */ |
26 | 26 | class Item extends \Phpfastcache\Drivers\Memory\Item |
27 | 27 | { |
28 | - public function __construct(ExtendedCacheItemPoolInterface $driver, string $key, EventManagerInterface $em) |
|
29 | - { |
|
30 | - trigger_error('Memstatic driver has changed its name, it is now called "Memory"', E_USER_DEPRECATED); |
|
31 | - parent::__construct($driver, $key, $em); |
|
32 | - } |
|
28 | + public function __construct(ExtendedCacheItemPoolInterface $driver, string $key, EventManagerInterface $em) |
|
29 | + { |
|
30 | + trigger_error('Memstatic driver has changed its name, it is now called "Memory"', E_USER_DEPRECATED); |
|
31 | + parent::__construct($driver, $key, $em); |
|
32 | + } |
|
33 | 33 | } |
@@ -25,9 +25,9 @@ |
||
25 | 25 | */ |
26 | 26 | class Driver extends \Phpfastcache\Drivers\Memory\Driver |
27 | 27 | { |
28 | - public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface $config, string $instanceId, EventManagerInterface $em) |
|
29 | - { |
|
30 | - trigger_error('Memstatic driver has changed its name, it is now called "Memory"', E_USER_DEPRECATED); |
|
31 | - parent::__construct($config, $instanceId, $em); |
|
32 | - } |
|
28 | + public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface $config, string $instanceId, EventManagerInterface $em) |
|
29 | + { |
|
30 | + trigger_error('Memstatic driver has changed its name, it is now called "Memory"', E_USER_DEPRECATED); |
|
31 | + parent::__construct($config, $instanceId, $em); |
|
32 | + } |
|
33 | 33 | } |
@@ -22,9 +22,9 @@ |
||
22 | 22 | */ |
23 | 23 | class Config extends \Phpfastcache\Drivers\Memory\Config |
24 | 24 | { |
25 | - public function __construct(array $parameters = []) |
|
26 | - { |
|
27 | - trigger_error('Memstatic driver has changed its name, it is now called "Memory"', E_USER_DEPRECATED); |
|
28 | - parent::__construct($parameters); |
|
29 | - } |
|
25 | + public function __construct(array $parameters = []) |
|
26 | + { |
|
27 | + trigger_error('Memstatic driver has changed its name, it is now called "Memory"', E_USER_DEPRECATED); |
|
28 | + parent::__construct($parameters); |
|
29 | + } |
|
30 | 30 | } |