diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c9fd2..2ffc38f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 9.2.2 +#### 29 July 2024 +- __Driver Core__ + - `Couchbasev4` Allow calling of `prepareToFork()` when driver is not initialized to allow switch between drivers. + - `Couchbasev4` Tell couchbase to reattach its threads if needed, while preparing to forking and on destruct. + ## 9.2.1 #### 25 April 2024 - __Driver Core__ diff --git a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php index d544fb7..332f016 100644 --- a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php +++ b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php @@ -90,6 +90,11 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve $this->__parentConstruct($config, $instanceId, $em); } + public function __destruct() + { + static::handleNotifyFork(); + } + /** * @return bool @@ -164,6 +169,7 @@ public static function prepareToFork(): void } if (\version_compare(static::$extVersion, '4.2.1', '>=')) { + static::handleNotifyFork(); Cluster::notifyFork(ForkEvent::PREPARE); } @@ -188,15 +194,20 @@ protected function handleForkedProcess(): void $this->connect(\posix_getppid()); } - if (\version_compare(static::$extVersion, '4.2.1', '>=')) { - if (static::$prepareToForkPPID === \posix_getpid()) { - Cluster::notifyFork(ForkEvent::PARENT); - } else { - Cluster::notifyFork(ForkEvent::CHILD); - } - static::$prepareToForkPPID = 0; - } + static::handleNotifyFork(); + } + } + } + + protected static function handleNotifyFork(): void + { + if (static::$prepareToForkPPID && \version_compare(static::$extVersion, '4.2.1', '>=')) { + if (static::$prepareToForkPPID === \posix_getpid()) { + Cluster::notifyFork(ForkEvent::PARENT); + } else { + Cluster::notifyFork(ForkEvent::CHILD); } + static::$prepareToForkPPID = 0; } } @@ -214,7 +225,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array /** * CouchbaseBucket::get() returns a GetResult interface */ - return $this->decodeDocument((array)$this->getCollection()->get($item->getEncodedKey())->content()); + return $this->decodeDocument((array) $this->getCollection()->get($item->getEncodedKey())->content()); } catch (DocumentNotFoundException) { return null; }