|
22 | 22 | use Couchbase\ClusterOptions; |
23 | 23 | use Couchbase\Collection; |
24 | 24 | use Couchbase\DocumentNotFoundException; |
| 25 | +use Couchbase\GetResult; |
25 | 26 | use Couchbase\Scope; |
26 | 27 | use Couchbase\UpsertOptions; |
27 | 28 | use DateTimeInterface; |
|
35 | 36 | use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException; |
36 | 37 | use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; |
37 | 38 | use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
| 39 | +use Phpfastcache\Exceptions\PhpfastcacheUnsupportedException; |
| 40 | +use Phpfastcache\Exceptions\PhpfastcacheUnsupportedMethodException; |
38 | 41 |
|
39 | 42 | /** |
40 | 43 | * @property Cluster $instance Instance of driver service |
@@ -105,6 +108,33 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array |
105 | 108 | } |
106 | 109 | } |
107 | 110 |
|
| 111 | + /** |
| 112 | + * @param ExtendedCacheItemInterface $item |
| 113 | + * @return ?array<string, mixed> |
| 114 | + */ |
| 115 | + protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array |
| 116 | + { |
| 117 | + try { |
| 118 | + $keys = $this->getKeys($items, true); |
| 119 | + $results = []; |
| 120 | + /** |
| 121 | + * CouchbaseBucket::get() returns a GetResult interface |
| 122 | + */ |
| 123 | + /** @var GetResult $document */ |
| 124 | + foreach ($this->getCollection()->getMulti($this->getKeys($items, true)) as $document) { |
| 125 | + $content = $document->content(); |
| 126 | + if ($content) { |
| 127 | + $decodedDocument = $this->decodeDocument($content); |
| 128 | + $results[$decodedDocument[ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX]] = $this->decodeDocument($content); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + return $results; |
| 133 | + } catch (DocumentNotFoundException) { |
| 134 | + return []; |
| 135 | + } |
| 136 | + } |
| 137 | + |
108 | 138 | /** |
109 | 139 | * @param ExtendedCacheItemInterface $item |
110 | 140 | * @return bool |
@@ -135,21 +165,47 @@ protected function driverDelete(string $key, string $encodedKey): bool |
135 | 165 | { |
136 | 166 |
|
137 | 167 | try { |
138 | | - $this->getCollection()->remove($encodedKey); |
139 | | - return true; |
| 168 | + return $this->getCollection()->remove($encodedKey)->mutationToken() !== null; |
140 | 169 | } catch (DocumentNotFoundException) { |
141 | 170 | return true; |
142 | 171 | } catch (CouchbaseException) { |
143 | 172 | return false; |
144 | 173 | } |
145 | 174 | } |
146 | 175 |
|
| 176 | + |
| 177 | + /** |
| 178 | + * @param string[] $keys |
| 179 | + * @return bool |
| 180 | + */ |
| 181 | + protected function driverDeleteMultiple(array $keys): bool |
| 182 | + { |
| 183 | + try { |
| 184 | + $this->getCollection()->removeMulti(array_map(fn(string $key) => $this->getEncodedKey($key), $keys)); |
| 185 | + return true; |
| 186 | + } catch (CouchbaseException) { |
| 187 | + return false; |
| 188 | + } |
| 189 | + } |
| 190 | + |
| 191 | + |
147 | 192 | /** |
148 | 193 | * @return bool |
| 194 | + * @throws PhpfastcacheUnsupportedMethodException |
149 | 195 | */ |
150 | 196 | protected function driverClear(): bool |
151 | 197 | { |
| 198 | + if (!$this->instance->buckets()->getBucket($this->getConfig()->getBucketName())->flushEnabled()) { |
| 199 | + $this->instance->buckets()->getBucket($this->getConfig()->getBucketName())->enableFlush(true); |
| 200 | + if (!$this->instance->buckets()->getBucket($this->getConfig()->getBucketName())->flushEnabled()) { |
| 201 | + throw new PhpfastcacheUnsupportedMethodException( |
| 202 | + 'Flushing operation is not enabled on your Bucket. See https://docs.couchbase.com/server/current/manage/manage-buckets/flush-bucket.html' |
| 203 | + ); |
| 204 | + } |
| 205 | + } |
| 206 | + |
152 | 207 | $this->instance->buckets()->flush($this->getConfig()->getBucketName()); |
| 208 | + |
153 | 209 | return true; |
154 | 210 | } |
155 | 211 |
|
|
0 commit comments