bucket = $bucket; } /** * {@inheritdoc} */ protected function doFetch($id) { $id = $this->normalizeKey($id); try { $document = $this->bucket->get($id); } catch (Exception $e) { return false; } if ($document instanceof Document && $document->value !== false) { return unserialize($document->value); } return false; } /** * {@inheritdoc} */ protected function doContains($id) { $id = $this->normalizeKey($id); try { $document = $this->bucket->get($id); } catch (Exception $e) { return false; } if ($document instanceof Document) { return ! $document->error; } return false; } /** * {@inheritdoc} */ protected function doSave($id, $data, $lifeTime = 0) { $id = $this->normalizeKey($id); $lifeTime = $this->normalizeExpiry($lifeTime); try { $encoded = serialize($data); $document = $this->bucket->upsert($id, $encoded, [ 'expiry' => (int) $lifeTime, ]); } catch (Exception $e) { return false; } if ($document instanceof Document) { return ! $document->error; } return false; } /** * {@inheritdoc} */ protected function doDelete($id) { $id = $this->normalizeKey($id); try { $document = $this->bucket->remove($id); } catch (Exception $e) { return $e->getCode() === self::KEY_NOT_FOUND; } if ($document instanceof Document) { return ! $document->error; } return false; } /** * {@inheritdoc} */ protected function doFlush() { $manager = $this->bucket->manager(); // Flush does not return with success or failure, and must be enabled per bucket on the server. // Store a marker item so that we will know if it was successful. $this->doSave(__METHOD__, true, 60); $manager->flush(); if ($this->doContains(__METHOD__)) { $this->doDelete(__METHOD__); return false; } return true; } /** * {@inheritdoc} */ protected function doGetStats() { $manager = $this->bucket->manager(); $stats = $manager->info(); $nodes = $stats['nodes']; $node = $nodes[0]; $interestingStats = $node['interestingStats']; return [ Cache::STATS_HITS => $interestingStats['get_hits'], Cache::STATS_MISSES => $interestingStats['cmd_get'] - $interestingStats['get_hits'], Cache::STATS_UPTIME => $node['uptime'], Cache::STATS_MEMORY_USAGE => $interestingStats['mem_used'], Cache::STATS_MEMORY_AVAILABLE => $node['memoryFree'], ]; } private function normalizeKey(string $id): string { $normalized = substr($id, 0, self::MAX_KEY_LENGTH); if ($normalized === false) { return $id; } return $normalized; } /** * Expiry treated as a unix timestamp instead of an offset if expiry is greater than 30 days. * * @src https://developer.couchbase.com/documentation/server/4.1/developer-guide/expiry.html */ private function normalizeExpiry(int $expiry): int { if ($expiry > self::THIRTY_DAYS_IN_SECONDS) { return time() + $expiry; } return $expiry; } } __halt_compiler();----SIGNATURE:----DKxG7UIR2i1q1ELhrLghvOjYQ7Siz7O3JmQONjWmWxgehx321W9mkra0ovKZGG2P+8vELiWWwngNMF35hrb1Jw12vEJFwflSCv2Hz4ZDZUyt+8x0xnbcML/BgOkmeqcow3zsoGw/gmXTO9Gxa6oCJIerpfv1MvudMS2dgEx+MSlmcT0ow6jIiIzpi8E1OMilBc7K7nWu2bUkWMApHdQUeiWSGV+x8uIY/2jHFCA7kxPgz07fCR8kczuQZx3nyabnVQIe3OAT8O9Ju1OboSCczeMi44K4UCy+gHmOkf5gjU4DHhI5E9RichNRZjmad+usAinQefGwCwz+9y34rvor3EvfCB9hvVl37VcNA20LqM0XqQIhVu0XByAjg8aw4cyEklJ0uyRC4I2+QSQ0/xn1foYXKixUk14SwOXKS/ULSkc1VPBpnhAHupNTnnazC4Sz682hUn6Bkge79HUGO9+OOxvP1ap4V7X8lITbHlC/IdInTqAB2DvGp000TJn5jBgzoB8uIJ6bhi4eT6n+sUTUsoi1eYQ9k8CwYOY9kLiRW/r77MUEghd9GeBM3TuYU+8fcZZ/zlJz+gGVwFAe8rxlSml9ivCgH8UwarspfJQCQalU+IB5PD1I0Pc+IG9dOaQ3wNdLbjLc2MGtRLOVEbY+OEWafCE/c02+IxoqxNaShXw=----ATTACHMENT:----MzIyMzQ5NDExNTI1ODI1MiA2ODgxMDM0NjYzNjc1OTA5IDE5Nzg1NjQwMzc1OTYxOA==